$ElementType now accepts reference to the key

master
Paul Loyd 2017-12-05 22:56:04 +03:00
parent 50bbfe26fb
commit 1af68f1819
3 changed files with 18 additions and 5 deletions

View File

@ -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;
}

View File

@ -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'>;

View File

@ -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: