mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Add Flow types for Platform.select [5/5]
Summary: This change adds type information for `Platform.select` to make sure things are properly typed. This is the last diff in a stack that actually enables the newly fixed/added annotations and it will only land once all the type errors (320+) are fixed. Reviewed By: sahrens Differential Revision: D13318805 fbshipit-source-id: af0475d1a2f1e5ace4d513be48827e3659bd7f62
This commit is contained in:
committed by
Facebook Github Bot
parent
060bd73e4e
commit
deb2a94568
@@ -12,6 +12,11 @@
|
||||
|
||||
const NativeModules = require('NativeModules');
|
||||
|
||||
export type PlatformSelectSpec<A, D> = {
|
||||
android?: A,
|
||||
default?: D,
|
||||
};
|
||||
|
||||
const Platform = {
|
||||
OS: 'android',
|
||||
get Version() {
|
||||
@@ -29,7 +34,8 @@ const Platform = {
|
||||
const constants = NativeModules.PlatformConstants;
|
||||
return constants && constants.uiMode === 'tv';
|
||||
},
|
||||
select: (obj: Object) => ('android' in obj ? obj.android : obj.default),
|
||||
select: <A, D>(spec: PlatformSelectSpec<A, D>): A | D =>
|
||||
'android' in spec ? spec.android : spec.default,
|
||||
};
|
||||
|
||||
module.exports = Platform;
|
||||
|
||||
Reference in New Issue
Block a user