Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

out of range index in a tuple magically works #5203

Closed
zpdDG4gta8XKpMCd opened this issue Oct 10, 2015 · 9 comments
Closed

out of range index in a tuple magically works #5203

zpdDG4gta8XKpMCd opened this issue Oct 10, 2015 · 9 comments
Labels
Committed The team has roadmapped this issue Good First Issue Well scoped, documented and has the green light Help Wanted You can do this Suggestion An idea for TypeScript

Comments

@zpdDG4gta8XKpMCd
Copy link

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

By design, isn't it?

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Oct 12, 2015
@RyanCavanaugh
Copy link
Member

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

@DanielRosenwasser
Copy link
Member

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).

@zpdDG4gta8XKpMCd
Copy link
Author

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.

@falsandtru
Copy link
Contributor

👍 This is invalid behavior.

@OliverJAsh
Copy link
Contributor

I ran into exactly the same issue.

@Igorbek
Copy link
Contributor

Igorbek commented Sep 19, 2016

See proposal #6229

@ghost
Copy link

ghost commented Aug 5, 2018

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

@RyanCavanaugh RyanCavanaugh added Committed The team has roadmapped this issue and removed In Discussion Not yet reached consensus labels Aug 6, 2018
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.1 milestone Aug 6, 2018
@RyanCavanaugh RyanCavanaugh added the Help Wanted You can do this label Aug 6, 2018
@RyanCavanaugh
Copy link
Member

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

@zpdDG4gta8XKpMCd
Copy link
Author

zpdDG4gta8XKpMCd commented Aug 6, 2018

god works in mysterious ways

@RyanCavanaugh RyanCavanaugh added the Good First Issue Well scoped, documented and has the green light label Aug 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Committed The team has roadmapped this issue Good First Issue Well scoped, documented and has the green light Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

6 participants