Support for Array<T> and $ReadOnlyArray<T>

master
Paul Loyd 2017-11-28 20:29:57 +03:00
parent 9941cbf380
commit d24a640ad5
3 changed files with 79 additions and 16 deletions

View File

@ -1,8 +1,29 @@
import {invariant} from './utils';
import type {Type} from './types';
export default {
Buffer() {
return {
kind: 'reference',
to: ["Buffer"],
to: ['Buffer'],
};
},
Array(params: (?Type)[]): ?Type {
invariant(params.length === 1);
invariant(params[0]);
return {
kind: 'array',
items: params[0],
};
},
$ReadOnlyArray(params: (?Type)[]): ?Type {
invariant(params.length === 1);
invariant(params[0]);
return {
kind: 'array',
items: params[0],
};
},
}

View File

@ -1,13 +1,19 @@
type Type = {
a: string[],
b: Array<string>,
c: $ReadOnlyArray<string>,
};
interface Interface {
a: string[];
b: Array<string>;
c: $ReadOnlyArray<string>;
}
class Class {
a: string[];
b: Array<string>;
c: $ReadOnlyArray<string>;
}
export {Type, Interface, Class};

View File

@ -3,29 +3,65 @@
{
"id": ["arrays", "Type"],
"kind": "record",
"fields": [{
"name": "a",
"value": {"kind": "array", "items": {"kind": "string"}},
"required": true
}]
"fields": [
{
"name": "a",
"value": {"kind": "array", "items": {"kind": "string"}},
"required": true
},
{
"name": "b",
"value": {"kind": "array", "items": {"kind": "string"}},
"required": true
},
{
"name": "c",
"value": {"kind": "array", "items": {"kind": "string"}},
"required": true
}
]
},
{
"id": ["arrays", "Interface"],
"kind": "record",
"fields": [{
"name": "a",
"value": {"kind": "array", "items": {"kind": "string"}},
"required": true
}]
"fields": [
{
"name": "a",
"value": {"kind": "array", "items": {"kind": "string"}},
"required": true
},
{
"name": "b",
"value": {"kind": "array", "items": {"kind": "string"}},
"required": true
},
{
"name": "c",
"value": {"kind": "array", "items": {"kind": "string"}},
"required": true
}
]
},
{
"id": ["arrays", "Class"],
"kind": "record",
"fields": [{
"name": "a",
"value": {"kind": "array", "items": {"kind": "string"}},
"required": true
}]
"fields": [
{
"name": "a",
"value": {"kind": "array", "items": {"kind": "string"}},
"required": true
},
{
"name": "b",
"value": {"kind": "array", "items": {"kind": "string"}},
"required": true
},
{
"name": "c",
"value": {"kind": "array", "items": {"kind": "string"}},
"required": true
}
]
}
]
}