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 {
|
function makeMaybe(ctx: Context, node: NullableTypeAnnotation): ?MaybeType {
|
||||||
const type = makeType(ctx, node.typeAnnotation);
|
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 {
|
function makeComplex(ctx: Context, node: ObjectTypeAnnotation): Type {
|
||||||
|
|
|
@ -59,7 +59,7 @@ function stripMaybe(params: (?Type)[], resolve: TypeId => Type): ?Type {
|
||||||
|
|
||||||
const maybe = resolve(ref.to);
|
const maybe = resolve(ref.to);
|
||||||
|
|
||||||
// TODO: support for unions and nested maybe.
|
// TODO: support for unions.
|
||||||
if (maybe.kind !== 'maybe') {
|
if (maybe.kind !== 'maybe') {
|
||||||
return t.clone(ref);
|
return t.clone(ref);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,15 @@
|
||||||
type X = {
|
type X = {
|
||||||
x: ?string,
|
x: ?string,
|
||||||
xx: ?string[],
|
xx: ?(?string),
|
||||||
xxx: (?string)[],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
interface Y {
|
interface Y {
|
||||||
y: ?string;
|
y: ?string[];
|
||||||
yy: ?string[];
|
yy: ?(?(?string));
|
||||||
yyy: (?string)[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Z {
|
class Z {
|
||||||
z: ?string;
|
z: (?string)[];
|
||||||
zz: ?string[];
|
|
||||||
zzz: (?string)[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export {X, Y, Z};
|
export {X, Y, Z};
|
||||||
|
|
|
@ -8,55 +8,27 @@
|
||||||
- name: xx
|
- name: xx
|
||||||
value:
|
value:
|
||||||
kind: maybe
|
kind: maybe
|
||||||
value:
|
value: {kind: string}
|
||||||
kind: array
|
|
||||||
items: {kind: string}
|
|
||||||
required: true
|
|
||||||
- name: xxx
|
|
||||||
value:
|
|
||||||
kind: array
|
|
||||||
items:
|
|
||||||
kind: maybe
|
|
||||||
value: {kind: string}
|
|
||||||
required: true
|
required: true
|
||||||
id: [maybe, X]
|
id: [maybe, X]
|
||||||
- kind: record
|
- kind: record
|
||||||
fields:
|
fields:
|
||||||
- name: y
|
- name: y
|
||||||
value:
|
|
||||||
kind: maybe
|
|
||||||
value: {kind: string}
|
|
||||||
required: true
|
|
||||||
- name: yy
|
|
||||||
value:
|
value:
|
||||||
kind: maybe
|
kind: maybe
|
||||||
value:
|
value:
|
||||||
kind: array
|
kind: array
|
||||||
items: {kind: string}
|
items: {kind: string}
|
||||||
required: true
|
required: true
|
||||||
- name: yyy
|
- name: yy
|
||||||
value:
|
value:
|
||||||
kind: array
|
kind: maybe
|
||||||
items:
|
value: {kind: string}
|
||||||
kind: maybe
|
|
||||||
value: {kind: string}
|
|
||||||
required: true
|
required: true
|
||||||
id: [maybe, Y]
|
id: [maybe, Y]
|
||||||
- kind: record
|
- kind: record
|
||||||
fields:
|
fields:
|
||||||
- name: z
|
- 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:
|
value:
|
||||||
kind: array
|
kind: array
|
||||||
items:
|
items:
|
||||||
|
|
Loading…
Reference in New Issue