Skip to content
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

Migration path from current DefinitelyTyped RN typings #10

Open
2 tasks
alloy opened this issue Dec 4, 2020 · 6 comments
Open
2 tasks

Migration path from current DefinitelyTyped RN typings #10

alloy opened this issue Dec 4, 2020 · 6 comments
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Milestone

Comments

@alloy
Copy link
Member

alloy commented Dec 4, 2020

This ticket describes the differences with the existing manually maintained DT typings and the migration path to these converted ones.

  • TypeScript does not have a build in way to deal with different files for different platforms. Proposal: Allow typescript to type check modules using react-native's module resolution TypeScript#21926

    • How can we offer distinctive sets of typings for iOS and Android (eg @types/react-native-ios, @types/react-native-android) and let the user configure them for their project?
    • Can DT handle this?
    • And can other DT packages that depend on RN use this too?
  • Many (all?) components are no longer class based, but rather function or even ‘abstract’ based. Because classes can be used as types in TS, there may be user code that refers to it that way but now needs to change to typeof View. This does not seem like an issue we need to resolve, as it’s simply not in line with reality. TS2749

  • Component props interfaces are exported, whereas upstream Flow code requires the user to do React.ElementProps<typeof View>. We currently export these separate props types as a migration convenience, but they are annotated as being deprecated.

    • There are many more component props interfaces still missing.
    • Should we add ElementProps to the React DT typings and is it correct that ElementProps does not include ref (as we use ComponentPropsWithoutRef of the React DT typings)?
  • Allow interface merging of RN NativeModules. These contain the user's own and 3rd party native modules and so should allow for the user to provide typings. f41628c

  • Style type param passed to StyleSheet.create<T>(…) needs to by a type alias, not an interface; because Index signature is missing in type (only on interfaces, not on type alias) TypeScript#15300 (comment). But also there's no longer a need to define the type upfront anymore (which perhaps was already no longer needed).

@alloy alloy added documentation Improvements or additions to documentation enhancement New feature or request labels Dec 4, 2020
@alloy
Copy link
Member Author

alloy commented Dec 7, 2020

We should consider providing a codemod that users can apply to their codebase to upgrade some/all of these.

@alloy
Copy link
Member Author

alloy commented Dec 9, 2020

  • TypeScript does not have a build in way to deal with different files for different platforms.

    • How can we offer distinctive sets of typings for iOS and Android (eg @types/react-native-ios, @types/react-native-android) and let the user configure them for their project?

Perhaps we can find a way to alias @types/react-native-ios to @types/react-native in tsconfig.json, that way people can have different configs per platform and importing from the react-native namespace should still work.

TS doesn't need to resolve specific extensions, as currently we’re generating distinctive sets per platform and dropping the platform file extension.

  • And can other DT packages that depend on RN use this too?

Additionally we could update the actual @types/react-native package to import and re-export the top-level exports of both @types/react-native-ios and @types/react-native-android so they can possibly depend on them in a platform independent manner? Unsure how feasible this is.

@alloy
Copy link
Member Author

alloy commented Dec 14, 2020

Could it help if we were able to release DT packages with version suffix? E.g. 0.64.0-ios and 0.64.0-android.

@alloy
Copy link
Member Author

alloy commented Dec 14, 2020

Also need to decide what to do with fallout in all DT packages that depend on the RN typings, assuming there will be.

@alloy
Copy link
Member Author

alloy commented Dec 16, 2020

One solution to providing the packages using alternate names would be to use declare module "react-native/..." {} for each module, e.g. see https://github.com/DefinitelyTyped/DefinitelyTyped/pull/49914/files#diff-8b9d499e69407ece17612b602d5355d8a1c8b2e5fdb6628e288638aab682ef29R7

@alloy alloy added this to the v1 milestone Jan 5, 2021
@alloy alloy self-assigned this Jan 5, 2021
@ZihanChen-MSFT
Copy link
Collaborator

Looks like TypeScript people are working on supporting this scenario

@ZihanChen-MSFT ZihanChen-MSFT modified the milestones: v1, v2 Jun 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants