mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 22:37:03 +00:00
[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.
This commit is contained in:
Vendored
+5
-24
@@ -9030,34 +9030,15 @@ export const Platform: PlatformStatic;
|
||||
export const PlatformIOS: PlatformIOSStatic;
|
||||
export const PixelRatio: PixelRatioStatic;
|
||||
|
||||
export interface ComponentInterface<P> {
|
||||
name?: string;
|
||||
displayName?: string;
|
||||
propTypes: PropTypes.ValidationMap<P>;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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<P, NP = {}>(
|
||||
viewName: string,
|
||||
componentInterface?: ComponentInterface<P>,
|
||||
extraConfig?: { nativeOnly?: NP }
|
||||
): React.ComponentClass<
|
||||
Partial<PropTypes.InferProps<PropTypes.ValidationMap<P>>> & { [K in keyof NP]?: any}
|
||||
>;
|
||||
export function requireNativeComponent(viewName: string): React.ReactType;
|
||||
|
||||
export function findNodeHandle(
|
||||
componentOrHandle: null | number | React.Component<any, any> | React.ComponentClass<any>
|
||||
|
||||
@@ -822,12 +822,7 @@ class BridgedComponentTest extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
const NativeBridgedComponent = requireNativeComponent("NativeBridgedComponent", BridgedComponentTest, {
|
||||
nativeOnly: {
|
||||
nativeProp: true,
|
||||
}
|
||||
});
|
||||
|
||||
const NativeBridgedComponent = requireNativeComponent("NativeBridgedComponent");
|
||||
|
||||
const SwitchColorTest = () => (
|
||||
<Switch trackColor={{ true: 'pink', false: 'red'}} />
|
||||
|
||||
Reference in New Issue
Block a user