TypeScript Version: 2.7.0-dev.20171226
Code
functiongetPromise(): Promise<[string,number]>{returnPromise.resolve(['',0]);}The above is an example, but it's not the only example of where TypeScript has trouble with tuples.
Others include:
leta: [string,number]=['',0];letb: [string,number]=a.slice();
The above one is harder, but it'd be great if array.slice() and array.slice(0) could be used to clone tuples.
https://github.com/Zarel/Pokemon-Showdown/blob/2b5654e307d7d65ee16c8bf55961b352c97c96e9/users.js#L1438
The above linked example disappeared when I tried to construct a simple equivalent testcase:
leta=nullas[string,string,object][]|null;if(a){a.push(['','',{}]);}else{a=[['','',{}]];}But if you care to clone that repo, checkout that commit, and delete the // @ts-ignore, you'll get a similar error message as the others, where the tuple degrades to an array.
Expected behavior:
No errors
Actual behavior:
test1.ts(2,2): error TS2322: Type 'Promise<(string | number)[]>' is not assignable to type 'Promise<[string, number]>'.
Type '(string | number)[]' is not assignable to type '[string, number]'.
Property '0' is missing in type '(string | number)[]'.
test1.ts(2,5): error TS2322: Type '(string | number)[]' is not assignable to type '[string, number]'.
Property '0' is missing in type '(string | number)[]'.
users.js(1438,4): error TS2322: Type '(string | Connection)[][]' is not assignable to type '[string, string, Connection][] | null'.
Type '(string | Connection)[][]' is not assignable to type '[string, string, Connection][]'.
Type '(string | Connection)[]' is not assignable to type '[string, string, Connection]'.
Property '0' is missing in type '(string | Connection)[]'.
TypeScript Version: 2.7.0-dev.20171226
Code
The above is an example, but it's not the only example of where TypeScript has trouble with tuples.
Others include:
The above one is harder, but it'd be great if
array.slice()andarray.slice(0)could be used to clone tuples.https://github.com/Zarel/Pokemon-Showdown/blob/2b5654e307d7d65ee16c8bf55961b352c97c96e9/users.js#L1438
The above linked example disappeared when I tried to construct a simple equivalent testcase:
But if you care to clone that repo, checkout that commit, and delete the
// @ts-ignore, you'll get a similar error message as the others, where the tuple degrades to an array.Expected behavior:
No errors
Actual behavior: