-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
[TS] Schema Types Generation #13460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TS] Schema Types Generation #13460
Conversation
Codecov Report
@@ Coverage Diff @@
## features/typescript #13460 +/- ##
=======================================================
- Coverage 56.69% 54.59% -2.11%
=======================================================
Files 958 1224 +266
Lines 21697 31089 +9392
Branches 3562 5645 +2083
=======================================================
+ Hits 12302 16972 +4670
- Misses 8395 12289 +3894
- Partials 1000 1828 +828
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few global comments before digging the code:
- Can you move this logic to the typescript utils so we just call them from the command ?
- Why not use typescript to build an ast and dump it to a file ?
it would avoid having to do all those string manipulations and would be easier to test & safer :)
f683462 to
7b89311
Compare
Nice insights, it's been implemented in 6c9b500 |
|
This pull request has been mentioned on Strapi Community Forum. There might be relevant details there: https://forum.strapi.io/t/typescript-support-has-been-added-to-4-3-0-beta-1/19517/2 |
I believe the only package that was still in
Yep, indeed.
What kind of errors do you see happening? Since we're getting the list of content types directly from a fully-loaded Strapi instance, I assumed any schema misconfiguration would be handled by Strapi validation steps. At first, I had a status column in the summary table as well as warning logs for things failings to build but I never encountered such scenarios and it ended up polluting the table output 🤷
I assumed that the verbose command was here to do that. I imagined that sometimes when piping commands or using it in CI or other tools, you might want to silence completely the command. |
|
This pull request has been mentioned on Strapi Community Forum. There might be relevant details there: https://forum.strapi.io/t/strapi-second-beta-release-for-v-4-3-0/20170/1 |
|
This pull request has been mentioned on Strapi Community Forum. There might be relevant details there: https://forum.strapi.io/t/typescript-support-has-been-added-to-4-3-0-beta-1/19517/5 |
|
Is there any ETA for this project? |
This feature will be released along with the TypeScript support feature whose ETA is the end of July. In the meantime, you can test it using |
I was more referring to an error in the generation (a usecase we missed for ex) that would break and just display a code error to the user. Would have been nice to wrap som of the generators with try catch to display "We could not generate type because of an unknown errors, please report it to ..."
We might want to go the other way around and have a -s silent option but display a minimum of info for the user to know what happened |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested the Date thing and I'm noticing a diff we might want to address.
If I set default: "date-string"
The attribute will be DefaultAttr<"date-string">
But if I put a date obj it will be DefaultAttr
I'm wondering if we should have DefaultAttr In the other case 🤔 that seems a bit inconsistent don't you think ?
|
One thing we could do is to extract the actual date value from the date instance and convert it to a string literal. But by doing this, we would lose the fact that we need an actual date instance. Another possible solution to keep consistency is to willingly use "Date" instead of the actual date string for default date-string values? |
What does it do?
Add a command to the CLI to automatically generate typings based on the application schemas, then load them in the
Strapi.Schemasglobal interface so that they can be used in the whole application.Why is it needed?
Develop experience improvement to automatically regenerate typings for local schemas (components and content types) and benefit from better typings everywhere in the application.
It'll also be necessary to have this tool when we'll start writing new types for the Strapi APIs, so that the types inference can be as good as possible.
How to test it?
examples/getstartedapplicationyarn strapi ts:generate-types--verboseto trigger the verbose mode--silentor-sto trigger the silent mode-oor--out-dirto specify the out directory in which the file will be created-for--fileto specific the filename that will contain the types declarations