Files
react-native/Libraries/Utilities/Platform.ios.js
T
Jordan Brown b60b70f7ce Improve typings for Platform.select on iOS
Summary:
There's no need for the 3 type arguments here. Flow will infer a union already if multiple properties are provided. Worse, by not providing these properties these tvars end up with no bounds, which can cause downstream constraints to stall. All of the suppresisons added here are for legitimate errors that were uncovered by consolidating to one type argument.

Changelog: [internal]

Reviewed By: SamChou19815

Differential Revision: D40355813

fbshipit-source-id: f02a101e5e32f3a2f660a34349e6416b9fde4124
2022-10-14 08:39:26 -07:00

74 lines
1.9 KiB
JavaScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow strict
*/
import NativePlatformConstantsIOS from './NativePlatformConstantsIOS';
export type PlatformSelectSpec<T> = {
default?: T,
native?: T,
ios?: T,
...
};
const Platform = {
__constants: null,
OS: 'ios',
// $FlowFixMe[unsafe-getters-setters]
get Version(): string {
// $FlowFixMe[object-this-reference]
return this.constants.osVersion;
},
// $FlowFixMe[unsafe-getters-setters]
get constants(): {|
forceTouchAvailable: boolean,
interfaceIdiom: string,
isTesting: boolean,
osVersion: string,
reactNativeVersion: {|
major: number,
minor: number,
patch: number,
prerelease: ?number,
|},
systemName: string,
|} {
// $FlowFixMe[object-this-reference]
if (this.__constants == null) {
// $FlowFixMe[object-this-reference]
this.__constants = NativePlatformConstantsIOS.getConstants();
}
// $FlowFixMe[object-this-reference]
return this.__constants;
},
// $FlowFixMe[unsafe-getters-setters]
get isPad(): boolean {
// $FlowFixMe[object-this-reference]
return this.constants.interfaceIdiom === 'pad';
},
// $FlowFixMe[unsafe-getters-setters]
get isTV(): boolean {
// $FlowFixMe[object-this-reference]
return this.constants.interfaceIdiom === 'tv';
},
// $FlowFixMe[unsafe-getters-setters]
get isTesting(): boolean {
if (__DEV__) {
// $FlowFixMe[object-this-reference]
return this.constants.isTesting;
}
return false;
},
select: <T>(spec: PlatformSelectSpec<T>): T =>
// $FlowFixMe[incompatible-return]
'ios' in spec ? spec.ios : 'native' in spec ? spec.native : spec.default,
};
module.exports = Platform;