Repository navigation
Support the React Native Strict TypeScript API - #828
Draft
collectioneur wants to merge 1 commit into
Draft
collectioneur wants to merge 1 commit into
collectioneur wants to merge 1 commit into
Conversation
Type the MarkdownTextInput instance as React.ComponentRef<typeof TextInput>. Under the Strict API, the default since React Native 0.87, TextInput is a function component, so `TextInput & React.Component` has no instance methods. On older React Native types it is the same TextInput class instance. Import the codegen types through the CodegenTypes namespace instead of the react-native/Libraries/Types/CodegenTypes deep import, which the Strict API blocks. The codegen schema is unchanged on React Native 0.80 and 0.85. React Native 0.79 exports no CodegenTypes and its codegen can't read qualified names, so the compatibility table drops it from the next release.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Details
React Native 0.87 made the Strict TypeScript API the default. Two things in Live Markdown's types don't work under it:
MarkdownTextInputis typed asTextInput & React.Component<MarkdownTextInputProps>. Under the Strict APITextInputis a function component, not a class, so this type has none of the instance methods (focus,blur,isFocused,setSelection,clear, ...). Apps that type the ref through it get errors on every call. It is nowReact.ComponentRef<typeof TextInput>, in bothMarkdownTextInput.tsxandMarkdownTextInput.web.tsx. On older React Native types this resolves to the sameTextInputclass instance, so nothing changes there.FloatandInt32fromreact-native/Libraries/Types/CodegenTypes, a deep import the Strict API blocks. It now uses theCodegenTypesnamespace exported fromreact-native.CodegenTypesis exported fromreact-nativesince 0.80, and codegen reads qualified names likeCodegenTypes.Floatsince 0.80 too. React Native 0.79 has neither, so the README compatibility table gets a0.1.373+row without 0.79, and0.1.362+becomes0.1.362 – 0.1.372.Related Issues
Expensify/App#101439
Manual Tests
npm run typecheckand ESLint pass on the changed files (React Native 0.85.3).MarkdownTextInputDecoratorViewNativeComponent.tswith the TypeScript parser of@react-native/codegen0.85.3 and 0.80.3. Both produce a schema byte for byte identical to the one frommain. With 0.79.7 the parser fails withUnknown prop type, which is why 0.79 is dropped..d.tsfiles of the installed package with these changes. Type-checking against the React Native 0.88.0 types removes 6 app errors. The App's regular type check on React Native 0.86 still passes.Linked PRs
MarkdownTextInputtype inAnimatedMarkdownTextInputRef. That workaround can be dropped once this is released.