TypeScript Version: 3.2.0
Code
This is the official demo
// Declare a tuple type
let x: [string, number];
// Actually,this code will throw error
x[3] = 'world'; // OK, 'string' can be assigned to 'string | number'
Expected behavior:
I want to know if this is a bug or this is document error
Actual behavior:
Tuple out of bounds will trow error, but document say When accessing an element outside the set of known indices, a union type is used instead
Playground Link:
https://www.tslang.cn/play/index.html#src=let%20x%3A%20%5Bstring%2C%20number%5D%3B%0D%0A%2F%2F%20When%20accessing%20an%20element%20outside%20the%20set%20of%20known%20indices%2C%20a%20union%20type%20is%20used%20instead%3A%0D%0A%2F%2F%20Actually%EF%BC%8Cthis%20code%20will%20throw%20error%0D%0Ax%5B3%5D%20%3D%20%22world%22%3B%20%2F%2F%20OK%2C%20'string'%20can%20be%20assigned%20to%20'string%20%7C%20number'

Related Issues: NO