From 65430a8a7b530420437b8f618849663dbef2d004 Mon Sep 17 00:00:00 2001 From: James Ide Date: Fri, 30 Nov 2018 10:17:33 -0800 Subject: [PATCH] [react-native] Make requireNativeComponent work with an update to @types/react 4dd9510a504875fb79a399d468e8f39e892af617 changed `React.ReactType` to look at entries in the `JSX.IntrinsicElements` map, which caused rendering `React.ReactType` elements to fail. This commit fixes the RN type declarations by returning `any`. We don't care about the actual return type that much -- it's concretely a string but externally, as a user of react-native, you'd want to only use it as a JSX component type and not as a string. And since it's a string that isn't registered with `JSX.IntrinsicElements`, there's no extra type information (ex: list of valid props) associated with it. Longer term, it might make sense for `@types/react-native` to add native component types like `RCTView` to `JSX.IntrinsicElements` and go back to using `React.ReactType<'RCTView'>` with `requireNativeComponent`, but this is a disruptive change. Test plan: Ran tests, verified they pass again. Fixes #30958. --- types/react-native/index.d.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index 6e54b6d7c9..ae1aa35f00 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -9037,8 +9037,11 @@ export const PixelRatio: PixelRatioStatic; * * const View = requireNativeComponent('RCTView'); * + * The concrete return type of `requireNativeComponent` is a string, but the declared type is + * `any` because TypeScript assumes anonymous JSX intrinsics (`string` instead of `"div", for + * example) not to have any props. */ -export function requireNativeComponent(viewName: string): React.ReactType; +export function requireNativeComponent(viewName: string): any; export function findNodeHandle( componentOrHandle: null | number | React.Component | React.ComponentClass