$ElementType now accepts reference to the key
parent
50bbfe26fb
commit
1af68f1819
|
@ -39,13 +39,13 @@ function elemType(params: (?Type)[], resolve: TypeId => Type): ?Type {
|
|||
|
||||
invariant(record.kind === 'record');
|
||||
|
||||
// TODO: support for references.
|
||||
invariant(key.kind === 'literal');
|
||||
invariant(typeof key.value === 'string');
|
||||
const prop = key.kind === 'reference' ? resolve(key.to) : key;
|
||||
|
||||
const field = wu(record.fields).find(field => field.name === key.value);
|
||||
invariant(prop.kind === 'literal');
|
||||
invariant(typeof prop.value === 'string');
|
||||
|
||||
const field = wu(record.fields).find(field => field.name === prop.value);
|
||||
|
||||
// TODO: what about removing "id"?
|
||||
return field ? t.clone(field.value) : null;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,11 @@ type X<T> = {
|
|||
x: T | string,
|
||||
};
|
||||
|
||||
type P = 'x';
|
||||
|
||||
type Y<T> = {
|
||||
y: $ElementType<X<boolean>, T>,
|
||||
yy: $ElementType<X<boolean>, P>,
|
||||
};
|
||||
|
||||
type Z = $PropertyType<Y<'x'>, 'y'>;
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
- {kind: string}
|
||||
required: true
|
||||
id: [elementType, X, boolean]
|
||||
- kind: literal
|
||||
value: x
|
||||
id: [elementType, P]
|
||||
- kind: record
|
||||
fields:
|
||||
- name: y
|
||||
|
@ -17,6 +20,13 @@
|
|||
- {kind: boolean}
|
||||
- {kind: string}
|
||||
required: true
|
||||
- name: yy
|
||||
value:
|
||||
kind: union
|
||||
variants:
|
||||
- {kind: boolean}
|
||||
- {kind: string}
|
||||
required: true
|
||||
id: [elementType, Y, x]
|
||||
- kind: union
|
||||
variants:
|
||||
|
|
Loading…
Reference in New Issue