TypeScript-Handbook
TypeScript-Handbook copied to clipboard
Is Tuple union type still work?
On http://www.typescriptlang.org/docs/handbook/basic-types.html , It said
When accessing an element outside the set of known indices, a union type is used instead
However, when I tested this example locally, both tsc and deno threw an error:
Type '"some string here"' is not assignable to type 'undefined'
Here is the example:
let x: [string, number];
x = ["hello", 10];
console.log('x[0].substr(1)', x[0].substr(1));
x[2] = 'world'; // Error was threw here
https://github.com/Microsoft/TypeScript/issues/28894#issuecomment-445370682 according to that comment tuples is now fixed length
Microsoft/TypeScript#28894 (comment) according to that comment tuples is now fixed length
Copy~thanks
https://github.com/Microsoft/TypeScript-Handbook/pull/998
I've created this pr, hope can fix it.