fix(types): support React Native 0.87 Strict TypeScript API - #697
Open
jslok wants to merge 1 commit into
Open
Conversation
RN 0.87 makes the Strict TypeScript API the default, which breaks two type-level assumptions in this package: - `react-native/Libraries/*` subpaths now resolve to `types: null`, so the deep `CodegenTypes` import has no types. RN re-exports the same types as a `CodegenTypes` namespace from the package root; `WithDefault<number, -1>` resolves identically, so codegen output is unchanged. - `View` is a function component, not a class, so it is no longer usable as a ref instance type. `React.ComponentRef<typeof View>` resolves to the instance type under both the legacy and strict typings. Verified with `tsc --noEmit` against react-native 0.87.1 in an app that uses both `captureRef` and `<ViewShot>`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01C55VgRJc8C6jJdtq1xZgLe
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.
RN 0.87 makes the Strict TypeScript API the default. Two type-level assumptions in this package break under it, and because
package.jsonexposessrc/index.tsxthrough thereact-nativeexport condition, consuming apps see the errors in their owntscrun:1.
CodegenTypesdeep import. RN'sexportsmap now sets"./Libraries/*": { "types": null }unless the consumer opts into thereact-native-legacy-deep-importscondition, so the deep import has no types. RN re-exports the same declarations as aCodegenTypesnamespace from the package root.CodegenTypes.WithDefault<number, -1>resolves to exactly the same type as before (number | null | undefined), so the generated native signature is unchanged.2.
Viewas a ref instance type. Under the strict typingsViewis a function component rather than a class, so it no longer describes an instance.React.ComponentRef<typeof View>extracts the instance type and resolves correctly under both the legacy and the strict typings, so this is not an RN-version-gated change.Compatibility note
The
CodegenTypesnamespace export landed in RN 0.80 (types_generated/Libraries/Types/CodegenTypesNamespace.d.ts); the current peer range is>=0.76.0. In practice the TurboModule spec only matters on the New Architecture, and v5's stack targets 0.81+, so I don't think anyone is affected — but if you'd rather not move the floor at all, the alternative is inliningtarget: number | null | undefinedand dropping the import entirely. Happy to switch if you prefer that.Verification
tsc --noEmitis clean againstreact-native@0.87.1+typescript@6.0.3in an app using bothcaptureRef()and<ViewShot>, with nocustomConditionsopt-out. No runtime code changed.🤖 Generated with Claude Code
https://claude.ai/code/session_01C55VgRJc8C6jJdtq1xZgLe