microsoft / TypeScript-Handbook

Deprecated, please use the TypeScript-Website repo instead
https://github.com/microsoft/TypeScript-Website
Apache License 2.0
4.88k stars 1.13k forks source link

Is Tuple union type still work? #975

Open xiaojingzhao opened 5 years ago

xiaojingzhao commented 5 years ago

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
ApolloTang commented 5 years ago

https://github.com/Microsoft/TypeScript/issues/28894#issuecomment-445370682 according to that comment tuples is now fixed length

xiaojingzhao commented 5 years ago

Microsoft/TypeScript#28894 (comment) according to that comment tuples is now fixed length

Copy~thanks

hateonion commented 5 years ago

https://github.com/Microsoft/TypeScript-Handbook/pull/998

I've created this pr, hope can fix it.