microsoft/TypeScript

out of range index in a tuple magically works

zpdDG4gta8XKpMCd opened this issue ยท 9 comments

var x : [number, number] = [1, 2];
var y = x[2]; // expected a compile error, actual ok

By design, isn't it?

It is currently per spec, but I don't think this behavior is desirable. This should probably be an error by some new rule.

Well the problem is that you're going to get that numeric index signature from Array<T>. There is another discussion about having an alternative interface for tuples at #4988 (comment).

I know guys you are trying your best, but I don't see an array, I only see a tuple which is not an array in a broad sense.

๐Ÿ‘ This is invalid behavior.

I ran into exactly the same issue.

See proposal #6229

It's now an error for tuples to have extra elements (#17765), so maybe we could revisit this? @sandersn @RyanCavanaugh

@Aleksey-Bykov the arc of language design is long but it bends toward justice. Accepting PRs

god works in mysterious ways