diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index 9f4fd748b5..10be75af8b 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -5569,7 +5569,8 @@ interface PlatformStatic { /** * @see https://facebook.github.io/react-native/docs/platform-specific-code.html#content */ - select(specifics: { [platform in PlatformOSType | 'default']?: T }): T; + select(specifics: ({ [platform in PlatformOSType]?: T } & { default: T }) | ({ [platform in PlatformOSType]: T })): T; + select(specifics: { [platform in PlatformOSType]?: T }): T | undefined; } interface PlatformIOSStatic extends PlatformStatic { diff --git a/types/react-native/test/index.tsx b/types/react-native/test/index.tsx index 3b388a9350..339ba8a7b9 100644 --- a/types/react-native/test/index.tsx +++ b/types/react-native/test/index.tsx @@ -21,6 +21,7 @@ import { CheckBox, ColorPropType, DataSourceAssetCallback, + DeviceEventEmitter, DeviceEventEmitterStatic, Dimensions, Image, @@ -242,7 +243,7 @@ const combinedStyle5: StyleProp = StyleSheet.compose( Math.random() < 0.5 ? composeTextStyle : null, ); -const combinedStyle6: StyleProp = StyleSheet.compose( +const combinedStyle6: StyleProp = StyleSheet.compose( null, null, ); @@ -438,7 +439,7 @@ export class SectionListTest extends React.Component, { } scrollMe = () => { - this.myList.current.scrollToLocation({ itemIndex: 0, sectionIndex: 1 }); + this.myList.current && this.myList.current.scrollToLocation({ itemIndex: 0, sectionIndex: 1 }); }; render() { @@ -661,7 +662,7 @@ const dataSourceAssetCallback1: DataSourceAssetCallback = { const dataSourceAssetCallback2: DataSourceAssetCallback = {}; // DeviceEventEmitterStatic -const deviceEventEmitterStatic: DeviceEventEmitterStatic = null; +const deviceEventEmitterStatic: DeviceEventEmitterStatic = DeviceEventEmitter; deviceEventEmitterStatic.addListener("keyboardWillShow", data => true); deviceEventEmitterStatic.addListener("keyboardWillShow", data => true, {}); @@ -726,7 +727,7 @@ class TextInputTest extends React.Component<{}, { username: string }> { render() { return ( - this.username.focus()}>Username + this.username && this.username.focus()}>Username (this.username = input)} @@ -776,7 +777,7 @@ export class ImageTest extends React.Component { const image: ImageResolvedAssetSource = Image.resolveAssetSource({ uri }); console.log(image.width, image.height, image.scale, image.uri); - Image.queryCache([uri]).then(({ [uri]: status }) => { + Image.queryCache && Image.queryCache([uri]).then(({ [uri]: status }) => { if (status === undefined) { console.log("Image is not in cache"); } else { @@ -985,6 +986,11 @@ const PlatformTest = () => { } }; +Platform.select({ android: 1 }); // $ExpectType number | undefined +Platform.select({ android: 1, ios: 2, default: 0 }); // $ExpectType number +Platform.select({ android: 1, ios: 2, macos: 3, web: 4, windows: 5 }); // $ExpectType number +Platform.select({ android: 1, ios: 2, macos: 3, web: 4, windows: 5, default: 0 }); // $ExpectType number + // ProgressBarAndroid const ProgressBarAndroidTest = () => {