mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Introduce NamedShape utility type
Summary:
Our CodegenSchema is littered with types that have the following shape
```
{
name: string,
optional: boolean,
typeAnnotation: ...
}
```
In all these types, the only difference is the typeAnnotation. This diff introduces a new utility type called `NamedShape`, that just creates this shape, given a type annotation. This should help reduce the amount of noise in the CodegenSchema, and make it a bit easier to read.
Changelog: [Internal]
Reviewed By: yungsters
Differential Revision: D24701331
fbshipit-source-id: a30d3e22933116e3dabf7929615905febacecba3
This commit is contained in:
committed by
Facebook GitHub Bot
parent
0e46080847
commit
856bc2978c
+27
-38
@@ -62,21 +62,24 @@ export type StringEnumTypeAnnotation = $ReadOnly<{|
|
||||
|}>,
|
||||
|}>;
|
||||
|
||||
export type EventObjectPropertyType = $ReadOnly<{|
|
||||
type NamedShape<+T> = $ReadOnly<{
|
||||
name: string,
|
||||
optional: boolean,
|
||||
typeAnnotation:
|
||||
| BooleanTypeAnnotation
|
||||
| StringTypeAnnotation
|
||||
| DoubleTypeAnnotation
|
||||
| FloatTypeAnnotation
|
||||
| Int32TypeAnnotation
|
||||
| StringEnumTypeAnnotation
|
||||
| $ReadOnly<{|
|
||||
type: 'ObjectTypeAnnotation',
|
||||
properties: $ReadOnlyArray<EventObjectPropertyType>,
|
||||
|}>,
|
||||
|}>;
|
||||
typeAnnotation: T,
|
||||
}>;
|
||||
|
||||
export type EventObjectPropertyType = NamedShape<
|
||||
| BooleanTypeAnnotation
|
||||
| StringTypeAnnotation
|
||||
| DoubleTypeAnnotation
|
||||
| FloatTypeAnnotation
|
||||
| Int32TypeAnnotation
|
||||
| StringEnumTypeAnnotation
|
||||
| $ReadOnly<{|
|
||||
type: 'ObjectTypeAnnotation',
|
||||
properties: $ReadOnlyArray<EventObjectPropertyType>,
|
||||
|}>,
|
||||
>;
|
||||
|
||||
type PropTypeTypeAnnotation =
|
||||
| $ReadOnly<{|
|
||||
@@ -161,11 +164,7 @@ type PropTypeTypeAnnotation =
|
||||
|}>,
|
||||
|}>;
|
||||
|
||||
export type PropTypeShape = $ReadOnly<{|
|
||||
name: string,
|
||||
optional: boolean,
|
||||
typeAnnotation: PropTypeTypeAnnotation,
|
||||
|}>;
|
||||
export type PropTypeShape = NamedShape<PropTypeTypeAnnotation>;
|
||||
|
||||
export type EventTypeShape = $ReadOnly<{|
|
||||
name: string,
|
||||
@@ -181,11 +180,7 @@ export type EventTypeShape = $ReadOnly<{|
|
||||
|}>,
|
||||
|}>;
|
||||
|
||||
export type CommandTypeShape = $ReadOnly<{|
|
||||
name: string,
|
||||
optional: boolean,
|
||||
typeAnnotation: CommandsFunctionTypeAnnotation,
|
||||
|}>;
|
||||
export type CommandTypeShape = NamedShape<CommandsFunctionTypeAnnotation>;
|
||||
|
||||
export type OptionsShape = $ReadOnly<{|
|
||||
interfaceOnly?: boolean,
|
||||
@@ -257,11 +252,9 @@ type NativeModuleSpec = $ReadOnly<{|
|
||||
properties: $ReadOnlyArray<NativeModulePropertySchema>,
|
||||
|}>;
|
||||
|
||||
export type NativeModulePropertySchema = $ReadOnly<{|
|
||||
name: string,
|
||||
optional: boolean,
|
||||
typeAnnotation: Nullable<NativeModuleFunctionTypeAnnotation>,
|
||||
|}>;
|
||||
export type NativeModulePropertySchema = NamedShape<
|
||||
Nullable<NativeModuleFunctionTypeAnnotation>,
|
||||
>;
|
||||
|
||||
export type NativeModuleAliasMap = $ReadOnly<{|
|
||||
[aliasName: string]: NativeModuleObjectTypeAnnotation,
|
||||
@@ -273,22 +266,18 @@ export type NativeModuleFunctionTypeAnnotation = $ReadOnly<{|
|
||||
returnTypeAnnotation: Nullable<NativeModuleReturnTypeAnnotation>,
|
||||
|}>;
|
||||
|
||||
export type NativeModuleMethodParamSchema = $ReadOnly<{|
|
||||
name: string,
|
||||
optional: boolean,
|
||||
typeAnnotation: Nullable<NativeModuleParamTypeAnnotation>,
|
||||
|}>;
|
||||
export type NativeModuleMethodParamSchema = NamedShape<
|
||||
Nullable<NativeModuleParamTypeAnnotation>,
|
||||
>;
|
||||
|
||||
export type NativeModuleObjectTypeAnnotation = $ReadOnly<{|
|
||||
type: 'ObjectTypeAnnotation',
|
||||
properties: $ReadOnlyArray<NativeModuleObjectTypeAnnotationPropertySchema>,
|
||||
|}>;
|
||||
|
||||
export type NativeModuleObjectTypeAnnotationPropertySchema = $ReadOnly<{|
|
||||
name: string,
|
||||
optional: boolean,
|
||||
typeAnnotation: Nullable<NativeModuleBaseTypeAnnotation>,
|
||||
|}>;
|
||||
export type NativeModuleObjectTypeAnnotationPropertySchema = NamedShape<
|
||||
Nullable<NativeModuleBaseTypeAnnotation>,
|
||||
>;
|
||||
|
||||
export type NativeModuleArrayTypeAnnotation<
|
||||
+T: Nullable<NativeModuleBaseTypeAnnotation>,
|
||||
|
||||
Reference in New Issue
Block a user