Allow primitivies without default values
Summary: It's not needed to keep required providing default values even if they are not actually relevant. Here I add a support for `null`, `0` of `false` instead by default and remove throwing errors if no other default value provided. Reviewed By: rubennorte Differential Revision: D16049047 fbshipit-source-id: bc4961af3873190568f2753fc4ec975354896df5
This commit is contained in:
Родитель
0f83dfab8e
Коммит
75d01075d4
|
@ -40,7 +40,7 @@ type NativeProps = $ReadOnly<{|
|
|||
enabled?: ?WithDefault<boolean, true>,
|
||||
items: $ReadOnlyArray<PickerItem>,
|
||||
prompt?: ?WithDefault<string, ''>,
|
||||
selected: WithDefault<Int32, 0>,
|
||||
selected: Int32,
|
||||
|
||||
// Events
|
||||
onSelect?: DirectEventHandler<PickerItemSelectEvent>,
|
||||
|
|
|
@ -40,7 +40,7 @@ type NativeProps = $ReadOnly<{|
|
|||
enabled?: ?WithDefault<boolean, true>,
|
||||
items: $ReadOnlyArray<PickerItem>,
|
||||
prompt?: ?WithDefault<string, ''>,
|
||||
selected: WithDefault<Int32, 0>,
|
||||
selected: Int32,
|
||||
|
||||
// Events
|
||||
onSelect?: DirectEventHandler<PickerItemSelectEvent>,
|
||||
|
|
|
@ -22,7 +22,7 @@ type NativeProps = $ReadOnly<{|
|
|||
//Props
|
||||
styleAttr?: string,
|
||||
typeAttr?: string,
|
||||
indeterminate: WithDefault<boolean, true>,
|
||||
indeterminate: boolean,
|
||||
progress?: WithDefault<Float, 0>,
|
||||
animating?: ?WithDefault<boolean, true>,
|
||||
color?: ?ColorValue,
|
||||
|
|
|
@ -61,7 +61,7 @@ type NativeProps = $ReadOnly<{|
|
|||
/**
|
||||
* Whether the view should be indicating an active refresh.
|
||||
*/
|
||||
refreshing: WithDefault<boolean, false>,
|
||||
refreshing: boolean,
|
||||
|}>;
|
||||
|
||||
export default codegenNativeComponent<NativeProps>('AndroidSwipeRefreshLayout');
|
||||
|
|
|
@ -40,7 +40,7 @@ type NativeProps = $ReadOnly<{|
|
|||
/**
|
||||
* Whether the view should be indicating an active refresh.
|
||||
*/
|
||||
refreshing: WithDefault<boolean, false>,
|
||||
refreshing: boolean,
|
||||
|}>;
|
||||
|
||||
export default codegenNativeComponent<NativeProps>('PullToRefreshView', {
|
||||
|
|
|
@ -19,7 +19,7 @@ type NativeProps = $ReadOnly<{|
|
|||
|
||||
// Props
|
||||
accessibilityHint?: WithDefault<string, ''>,
|
||||
accessibilityRole?: WithDefault<string, null>,
|
||||
accessibilityRole?: string,
|
||||
|}>;
|
||||
|
||||
export default codegenNativeComponent<NativeProps>('StringPropNativeComponent');
|
||||
|
|
|
@ -158,43 +158,41 @@ type ModuleProps = $ReadOnly<{|
|
|||
|
||||
// Props
|
||||
// Boolean props
|
||||
boolean_required: WithDefault<boolean, true>,
|
||||
boolean_required: boolean,
|
||||
boolean_optional_key?: WithDefault<boolean, true>,
|
||||
boolean_optional_value: ?WithDefault<boolean, true>,
|
||||
boolean_optional_both?: ?WithDefault<boolean, true>,
|
||||
|
||||
// String props
|
||||
string_required: WithDefault<string, ''>,
|
||||
string_required: string,
|
||||
string_optional_key?: WithDefault<string, ''>,
|
||||
string_optional_value: ?WithDefault<string, ''>,
|
||||
string_optional_both?: ?WithDefault<string, ''>,
|
||||
|
||||
// String props, null default
|
||||
string_null_required: WithDefault<string, null>,
|
||||
string_null_optional_key?: WithDefault<string, null>,
|
||||
string_null_optional_value: ?WithDefault<string, null>,
|
||||
string_null_optional_both?: ?WithDefault<string, null>,
|
||||
|
||||
// Stringish props
|
||||
stringish_required: WithDefault<Stringish, ''>,
|
||||
stringish_required: Stringish,
|
||||
stringish_optional_key?: WithDefault<Stringish, ''>,
|
||||
stringish_optional_value: ?WithDefault<Stringish, ''>,
|
||||
stringish_optional_both?: ?WithDefault<Stringish, ''>,
|
||||
|
||||
// Stringish props, null default
|
||||
stringish_null_required: WithDefault<Stringish, null>,
|
||||
stringish_null_optional_key?: WithDefault<Stringish, null>,
|
||||
stringish_null_optional_value: ?WithDefault<Stringish, null>,
|
||||
stringish_null_optional_both?: ?WithDefault<Stringish, null>,
|
||||
|
||||
// Float props
|
||||
float_required: WithDefault<Float, 1.1>,
|
||||
float_required: Float,
|
||||
float_optional_key?: WithDefault<Float, 1.1>,
|
||||
float_optional_value: ?WithDefault<Float, 1.1>,
|
||||
float_optional_both?: ?WithDefault<Float, 1.1>,
|
||||
|
||||
// Int32 props
|
||||
int32_required: WithDefault<Int32, 1>,
|
||||
int32_required: Int32,
|
||||
int32_optional_key?: WithDefault<Int32, 1>,
|
||||
int32_optional_value: ?WithDefault<Int32, 1>,
|
||||
int32_optional_both?: ?WithDefault<Int32, 1>,
|
||||
|
|
|
@ -25,7 +25,7 @@ Object {
|
|||
"name": "boolean_required",
|
||||
"optional": false,
|
||||
"typeAnnotation": Object {
|
||||
"default": true,
|
||||
"default": false,
|
||||
"type": "BooleanTypeAnnotation",
|
||||
},
|
||||
},
|
||||
|
@ -57,7 +57,7 @@ Object {
|
|||
"name": "string_required",
|
||||
"optional": false,
|
||||
"typeAnnotation": Object {
|
||||
"default": "",
|
||||
"default": null,
|
||||
"type": "StringTypeAnnotation",
|
||||
},
|
||||
},
|
||||
|
@ -85,14 +85,6 @@ Object {
|
|||
"type": "StringTypeAnnotation",
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"name": "string_null_required",
|
||||
"optional": false,
|
||||
"typeAnnotation": Object {
|
||||
"default": null,
|
||||
"type": "StringTypeAnnotation",
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"name": "string_null_optional_key",
|
||||
"optional": true,
|
||||
|
@ -121,7 +113,7 @@ Object {
|
|||
"name": "stringish_required",
|
||||
"optional": false,
|
||||
"typeAnnotation": Object {
|
||||
"default": "",
|
||||
"default": null,
|
||||
"type": "StringTypeAnnotation",
|
||||
},
|
||||
},
|
||||
|
@ -149,14 +141,6 @@ Object {
|
|||
"type": "StringTypeAnnotation",
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"name": "stringish_null_required",
|
||||
"optional": false,
|
||||
"typeAnnotation": Object {
|
||||
"default": null,
|
||||
"type": "StringTypeAnnotation",
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"name": "stringish_null_optional_key",
|
||||
"optional": true,
|
||||
|
@ -185,7 +169,7 @@ Object {
|
|||
"name": "float_required",
|
||||
"optional": false,
|
||||
"typeAnnotation": Object {
|
||||
"default": 1.1,
|
||||
"default": 0,
|
||||
"type": "FloatTypeAnnotation",
|
||||
},
|
||||
},
|
||||
|
@ -217,7 +201,7 @@ Object {
|
|||
"name": "int32_required",
|
||||
"optional": false,
|
||||
"typeAnnotation": Object {
|
||||
"default": 1,
|
||||
"default": 0,
|
||||
"type": "Int32TypeAnnotation",
|
||||
},
|
||||
},
|
||||
|
|
|
@ -129,29 +129,20 @@ function getTypeAnnotation(name, typeAnnotation, defaultValue) {
|
|||
name: 'PointPrimitive',
|
||||
};
|
||||
case 'Int32':
|
||||
if (defaultValue != null) {
|
||||
return {
|
||||
type: 'Int32TypeAnnotation',
|
||||
default: (defaultValue: number),
|
||||
};
|
||||
}
|
||||
throw new Error(`A default int is required for "${name}"`);
|
||||
return {
|
||||
type: 'Int32TypeAnnotation',
|
||||
default: ((defaultValue ? defaultValue : 0): number),
|
||||
};
|
||||
case 'Float':
|
||||
if (defaultValue != null) {
|
||||
return {
|
||||
type: 'FloatTypeAnnotation',
|
||||
default: (defaultValue: number),
|
||||
};
|
||||
}
|
||||
throw new Error(`A default float is required for "${name}"`);
|
||||
return {
|
||||
type: 'FloatTypeAnnotation',
|
||||
default: ((defaultValue ? defaultValue : 0): number),
|
||||
};
|
||||
case 'BooleanTypeAnnotation':
|
||||
if (defaultValue != null) {
|
||||
return {
|
||||
type: 'BooleanTypeAnnotation',
|
||||
default: (defaultValue: boolean),
|
||||
};
|
||||
}
|
||||
throw new Error(`A default boolean is required for "${name}"`);
|
||||
return {
|
||||
type: 'BooleanTypeAnnotation',
|
||||
default: ((defaultValue == null ? false : defaultValue): boolean),
|
||||
};
|
||||
case 'StringTypeAnnotation':
|
||||
if (typeof defaultValue !== 'undefined') {
|
||||
return {
|
||||
|
|
Загрузка…
Ссылка в новой задаче