Unwrap nested maybes
parent
b4244fc196
commit
b8e69e10a4
|
@ -141,7 +141,11 @@ function makeType(ctx: Context, node: FlowTypeAnnotation): ?Type {
|
|||
function makeMaybe(ctx: Context, node: NullableTypeAnnotation): ?MaybeType {
|
||||
const type = makeType(ctx, node.typeAnnotation);
|
||||
|
||||
return type != null ? t.createMaybe(type) : null;
|
||||
if (!type) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return type.kind === 'maybe' ? type : t.createMaybe(type);
|
||||
}
|
||||
|
||||
function makeComplex(ctx: Context, node: ObjectTypeAnnotation): Type {
|
||||
|
|
|
@ -59,7 +59,7 @@ function stripMaybe(params: (?Type)[], resolve: TypeId => Type): ?Type {
|
|||
|
||||
const maybe = resolve(ref.to);
|
||||
|
||||
// TODO: support for unions and nested maybe.
|
||||
// TODO: support for unions.
|
||||
if (maybe.kind !== 'maybe') {
|
||||
return t.clone(ref);
|
||||
}
|
||||
|
|
|
@ -1,19 +1,15 @@
|
|||
type X = {
|
||||
x: ?string,
|
||||
xx: ?string[],
|
||||
xxx: (?string)[],
|
||||
xx: ?(?string),
|
||||
};
|
||||
|
||||
interface Y {
|
||||
y: ?string;
|
||||
yy: ?string[];
|
||||
yyy: (?string)[];
|
||||
y: ?string[];
|
||||
yy: ?(?(?string));
|
||||
}
|
||||
|
||||
class Z {
|
||||
z: ?string;
|
||||
zz: ?string[];
|
||||
zzz: (?string)[];
|
||||
z: (?string)[];
|
||||
}
|
||||
|
||||
export {X, Y, Z};
|
||||
|
|
|
@ -7,15 +7,6 @@
|
|||
required: true
|
||||
- name: xx
|
||||
value:
|
||||
kind: maybe
|
||||
value:
|
||||
kind: array
|
||||
items: {kind: string}
|
||||
required: true
|
||||
- name: xxx
|
||||
value:
|
||||
kind: array
|
||||
items:
|
||||
kind: maybe
|
||||
value: {kind: string}
|
||||
required: true
|
||||
|
@ -23,21 +14,14 @@
|
|||
- kind: record
|
||||
fields:
|
||||
- name: y
|
||||
value:
|
||||
kind: maybe
|
||||
value: {kind: string}
|
||||
required: true
|
||||
- name: yy
|
||||
value:
|
||||
kind: maybe
|
||||
value:
|
||||
kind: array
|
||||
items: {kind: string}
|
||||
required: true
|
||||
- name: yyy
|
||||
- name: yy
|
||||
value:
|
||||
kind: array
|
||||
items:
|
||||
kind: maybe
|
||||
value: {kind: string}
|
||||
required: true
|
||||
|
@ -45,18 +29,6 @@
|
|||
- kind: record
|
||||
fields:
|
||||
- name: z
|
||||
value:
|
||||
kind: maybe
|
||||
value: {kind: string}
|
||||
required: true
|
||||
- name: zz
|
||||
value:
|
||||
kind: maybe
|
||||
value:
|
||||
kind: array
|
||||
items: {kind: string}
|
||||
required: true
|
||||
- name: zzz
|
||||
value:
|
||||
kind: array
|
||||
items:
|
||||
|
|
Loading…
Reference in New Issue