TypeScript-Handbook icon indicating copy to clipboard operation
TypeScript-Handbook copied to clipboard

Is Tuple union type still work?

Open xiaojingzhao opened this issue 6 years ago • 3 comments
trafficstars

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

xiaojingzhao avatar Feb 26 '19 01:02 xiaojingzhao

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

ApolloTang avatar Mar 04 '19 07:03 ApolloTang

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

Copy~thanks

xiaojingzhao avatar Mar 05 '19 05:03 xiaojingzhao

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

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

hateonion avatar Mar 28 '19 03:03 hateonion