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

Remove destructive methods in tuple type #6325

Closed
falsandtru opened this issue Jan 2, 2016 · 3 comments
Closed

Remove destructive methods in tuple type #6325

falsandtru opened this issue Jan 2, 2016 · 3 comments
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript

Comments

@falsandtru
Copy link
Contributor

I think, tuple type should not have destructive methods because these methods break consistency between the interface and actual properties.

  • Array#push
  • Array#pop
  • Array#shift
  • Array#unshift
  • Array#splice
var t: [boolean, number];
t.shift(); // now actual t type is [number]
@DanielRosenwasser
Copy link
Member

I'm not sure we'd be willing to take that breaking change, but there is discussion at #4988 (comment) regarding an alternative interface from tuple types.

@DanielRosenwasser DanielRosenwasser added the Suggestion An idea for TypeScript label Jan 4, 2016
@zpdDG4gta8XKpMCd
Copy link

@falsandtru, you might also find the following helpful, provided whole awkwardness of tuples in TypeScript:

interface T2<a, b> {
    0: a;
    1: b;
}
function t2<a, b>(one: a, another: b) : T2<a, b> {
    return <any> [one, another];
}

let pair = t2('hey', true);
let text = pair[0];
let flag = pair[1];
let problem = pair[2];

UPDATE: fixed indices

@mhegazy mhegazy added the Declined The issue was declined as something which matches the TypeScript vision label Jan 4, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Jan 4, 2016

Tuples are just arrays. and thus can have these methods. at least this is the current design. @Aleksey-Bykov's answer should allow you to limit your tuples to a more strict subset.

@mhegazy mhegazy closed this as completed Jan 4, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants