From 797f19a5eb36bdf78d82e52ff5651a020b192e48 Mon Sep 17 00:00:00 2001 From: James Ide Date: Tue, 27 Nov 2018 14:50:09 -0800 Subject: [PATCH] [react-native] Update type definition for requireNativeComponent for 0.57.x requireNativeComponent now only takes a string and returns a string. See the definition here: https://github.com/facebook/react-native/blob/1151c096dab17e5d9a6ac05b61aacecd4305f3db/Libraries/ReactNative/requireNativeComponent.js#L24-L27. The return type here is specified as `React.ReactType`, which is a union type that includes strings. We can't use `string` because TypeScript treats it as an intrinsic element like `div` and thinks it has no props. Updated the corresponding test code too. --- types/react-native/index.d.ts | 29 +++++------------------------ types/react-native/test/index.tsx | 7 +------ 2 files changed, 6 insertions(+), 30 deletions(-) diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index 9e68e283a9..6e54b6d7c9 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -9030,34 +9030,15 @@ export const Platform: PlatformStatic; export const PlatformIOS: PlatformIOSStatic; export const PixelRatio: PixelRatioStatic; -export interface ComponentInterface

{ - name?: string; - displayName?: string; - propTypes: PropTypes.ValidationMap

; -} - /** - * Used to create React components that directly wrap native component - * implementations. Config information is extracted from data exported from the - * UIManager module. You should also wrap the native component in a - * hand-written component with full propTypes definitions and other - * documentation - pass the hand-written component in as `componentInterface` to - * verify all the native props are documented via `propTypes`. + * Creates values that can be used like React components which represent native + * view managers. You should create JavaScript modules that wrap these values so + * that the results are memoized. Example: * - * If some native props shouldn't be exposed in the wrapper interface, you can - * pass null for `componentInterface` and call `verifyPropTypes` directly - * with `nativePropsToIgnore`; + * const View = requireNativeComponent('RCTView'); * - * Common types are lined up with the appropriate prop differs with - * `TypeToDifferMap`. Non-scalar types not in the map default to `deepDiffer`. */ -export function requireNativeComponent( - viewName: string, - componentInterface?: ComponentInterface

, - extraConfig?: { nativeOnly?: NP } -): React.ComponentClass< - Partial>> & { [K in keyof NP]?: any} ->; +export function requireNativeComponent(viewName: string): React.ReactType; export function findNodeHandle( componentOrHandle: null | number | React.Component | React.ComponentClass diff --git a/types/react-native/test/index.tsx b/types/react-native/test/index.tsx index 56d6b7035b..b5d7a5faeb 100644 --- a/types/react-native/test/index.tsx +++ b/types/react-native/test/index.tsx @@ -822,12 +822,7 @@ class BridgedComponentTest extends React.Component { } } -const NativeBridgedComponent = requireNativeComponent("NativeBridgedComponent", BridgedComponentTest, { - nativeOnly: { - nativeProp: true, - } -}); - +const NativeBridgedComponent = requireNativeComponent("NativeBridgedComponent"); const SwitchColorTest = () => (