$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'); invariant(record.kind === 'record');
// TODO: support for references. const prop = key.kind === 'reference' ? resolve(key.to) : key;
invariant(key.kind === 'literal');
invariant(typeof key.value === 'string');
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; return field ? t.clone(field.value) : null;
} }

View File

@ -2,8 +2,11 @@ type X<T> = {
x: T | string, x: T | string,
}; };
type P = 'x';
type Y<T> = { type Y<T> = {
y: $ElementType<X<boolean>, T>, y: $ElementType<X<boolean>, T>,
yy: $ElementType<X<boolean>, P>,
}; };
type Z = $PropertyType<Y<'x'>, 'y'>; type Z = $PropertyType<Y<'x'>, 'y'>;

View File

@ -8,6 +8,9 @@
- {kind: string} - {kind: string}
required: true required: true
id: [elementType, X, boolean] id: [elementType, X, boolean]
- kind: literal
value: x
id: [elementType, P]
- kind: record - kind: record
fields: fields:
- name: y - name: y
@ -17,6 +20,13 @@
- {kind: boolean} - {kind: boolean}
- {kind: string} - {kind: string}
required: true required: true
- name: yy
value:
kind: union
variants:
- {kind: boolean}
- {kind: string}
required: true
id: [elementType, Y, x] id: [elementType, Y, x]
- kind: union - kind: union
variants: variants: