Skip to content

Support the React Native Strict TypeScript API - #828

Draft
collectioneur wants to merge 1 commit into
Expensify:mainfrom
collectioneur:collectioneur/strict-api-types
Draft

collectioneur wants to merge 1 commit into
Expensify:mainfrom
collectioneur:collectioneur/strict-api-types

Conversation

@collectioneur

Copy link
Copy Markdown
Contributor

Details

React Native 0.87 made the Strict TypeScript API the default. Two things in Live Markdown's types don't work under it:

  • MarkdownTextInput is typed as TextInput & React.Component<MarkdownTextInputProps>. Under the Strict API TextInput is 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 now React.ComponentRef<typeof TextInput>, in both MarkdownTextInput.tsx and MarkdownTextInput.web.tsx. On older React Native types this resolves to the same TextInput class instance, so nothing changes there.
  • The codegen spec imports Float and Int32 from react-native/Libraries/Types/CodegenTypes, a deep import the Strict API blocks. It now uses the CodegenTypes namespace exported from react-native.

CodegenTypes is exported from react-native since 0.80, and codegen reads qualified names like CodegenTypes.Float since 0.80 too. React Native 0.79 has neither, so the README compatibility table gets a 0.1.373+ row without 0.79, and 0.1.362+ becomes 0.1.362 – 0.1.372.

Related Issues

Expensify/App#101439

Manual Tests

  • npm run typecheck and ESLint pass on the changed files (React Native 0.85.3).
  • I parsed MarkdownTextInputDecoratorViewNativeComponent.ts with the TypeScript parser of @react-native/codegen 0.85.3 and 0.80.3. Both produce a schema byte for byte identical to the one from main. With 0.79.7 the parser fails with Unknown prop type, which is why 0.79 is dropped.
  • In Expensify/App, I replaced the .d.ts files 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.
  • I did not build the example app.

Linked PRs

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant