mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-16 23:10:29 +00:00
Improve null type checking of Platform.select (#41455)
This commit is contained in:
Vendored
+2
-1
@@ -5569,7 +5569,8 @@ interface PlatformStatic {
|
||||
/**
|
||||
* @see https://facebook.github.io/react-native/docs/platform-specific-code.html#content
|
||||
*/
|
||||
select<T>(specifics: { [platform in PlatformOSType | 'default']?: T }): T;
|
||||
select<T>(specifics: ({ [platform in PlatformOSType]?: T } & { default: T }) | ({ [platform in PlatformOSType]: T })): T;
|
||||
select<T>(specifics: { [platform in PlatformOSType]?: T }): T | undefined;
|
||||
}
|
||||
|
||||
interface PlatformIOSStatic extends PlatformStatic {
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
CheckBox,
|
||||
ColorPropType,
|
||||
DataSourceAssetCallback,
|
||||
DeviceEventEmitter,
|
||||
DeviceEventEmitterStatic,
|
||||
Dimensions,
|
||||
Image,
|
||||
@@ -242,7 +243,7 @@ const combinedStyle5: StyleProp<TextStyle> = StyleSheet.compose(
|
||||
Math.random() < 0.5 ? composeTextStyle : null,
|
||||
);
|
||||
|
||||
const combinedStyle6: StyleProp<TextStyle> = StyleSheet.compose(
|
||||
const combinedStyle6: StyleProp<TextStyle | null> = StyleSheet.compose(
|
||||
null,
|
||||
null,
|
||||
);
|
||||
@@ -438,7 +439,7 @@ export class SectionListTest extends React.Component<SectionListProps<string>, {
|
||||
}
|
||||
|
||||
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 (
|
||||
<View>
|
||||
<Text onPress={() => this.username.focus()}>Username</Text>
|
||||
<Text onPress={() => this.username && this.username.focus()}>Username</Text>
|
||||
|
||||
<TextInput
|
||||
ref={input => (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 = () => {
|
||||
<ProgressBarAndroid
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"lib": ["es6"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"jsx": "react",
|
||||
|
||||
Reference in New Issue
Block a user