-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Fix codegen to add T
of Promise<T>
in CodegenSchema.js
#35345
Conversation
Base commit: 6e9d3bf |
Base commit: 6e9d3bf |
PR build artifact for d396973 is ready. |
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.
Please take a look at the comments. Thanks!
packages/react-native-codegen/src/parsers/__tests__/parsers-primitives-test.js
Outdated
Show resolved
Hide resolved
packages/react-native-codegen/src/parsers/parsers-primitives.js
Outdated
Show resolved
Hide resolved
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.
Hi @ZihanChen-MSFT, thank you so much for this addition.
I think we should slightly change the signature of the methods and try to keep the functions simpler not to hide side effects and additional computation in them.
I left some comments pointing out what I mean.
packages/react-native-codegen/src/parsers/parsers-primitives.js
Outdated
Show resolved
Hide resolved
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
I don't know why I can only "Re-request review" for one reviewer, if I click another, the original one will be reset. |
PR build artifact for fa1e1f7 is ready. |
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
I did some internal research on the issue @ZihanChen-MSFT and @christophpurrer. Internally, we have modules that returns these type of promises:
For the Array, I think we have to support them as proper generic type inside a promise. It make sense to have a function in a module that returns a list of something. The The Otherwise, the easy way for the last three is to threat the What do you think? |
@cipolleschi Hi, I've submitted one last commit and with a small fix it could support all types except Fully supporting union as nullable will add a big piece of code, and I don't think I want to make so many changes into one PR. Fixing the same thing in TypeScript already introduced multiple PRs. Doing this in Flow could not be easier. Do you think it is acceptable to skip the type if it is not recognized? The previous version didn't check them at all, so by doing this it doesn't make things worse. By the way, |
PR build artifact for c933fa0 is ready. |
PR build artifact for 444d943 is ready. |
:( We have another type that did not pop up earlier: export type AuthorizationStatus = 'authorized' | 'denied' | 'undetermined'; And the error is:
Which is a bit weird, because it should have been catched by the latest changes, right? |
But the type is actually supported, I've tested that in a new submitted test case. |
PR build artifact for b7d90ec is ready. |
My bad, the error was much subtler than what I understood at first sight. So, the failing example is something like this:
And it fails when emitting the |
b7d90ec
to
c3a65c0
Compare
@cipolleschi Hi, I add a new test case and fix the issue. I think |
|
PR build artifact for c3a65c0 is ready. |
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.
Thanks for the changes, they make sense to me. Also, many thanks for adding those tests: they should help us keeping an eye on those changes.
Let me import the PR and see if the internal CI is happy with the changes! :D
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
This pull request was successfully merged by @ZihanChen-MSFT in 8a38e03. When will my fix make it into a release? | Upcoming Releases |
…35345) Summary: `Promise<T>` is used very often in turbo module as function return types. So `T` is a critical thing for type safety. To enable future generator to produce more specific type for `Promise`, `T` is added to the schema. ## Changelog [General] [Changed] - Fix codegen to add `T` of `Promise<T>` in CodegenSchema.js Pull Request resolved: facebook#35345 Test Plan: `yarn jest react-native-codegen` passed Reviewed By: lunaleaps Differential Revision: D41304647 Pulled By: cipolleschi fbshipit-source-id: 6cdd2357b83d4d8007c881a7090cbb8969f3ae9d
Summary
Promise<T>
is used very often in turbo module as function return types. SoT
is a critical thing for type safety. To enable future generator to produce more specific type forPromise
,T
is added to the schema.Changelog
[General] [Changed] - Fix codegen to add
T
ofPromise<T>
in CodegenSchema.jsTest Plan
yarn jest react-native-codegen
passed