Skip to content

Incorrect typing when calling splice() on a tuple #45355

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

Closed
bbrk24 opened this issue Aug 7, 2021 · 3 comments
Closed

Incorrect typing when calling splice() on a tuple #45355

bbrk24 opened this issue Aug 7, 2021 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@bbrk24
Copy link

bbrk24 commented Aug 7, 2021

Bug Report

πŸ”Ž Search Terms

tuple splice

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried. I reviewed the FAQ for entries about tuples, but didn't find anything.

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

declare let arr: [string, number];

arr.splice(1); // mutates arr, making it only [string]
let arr2 = arr; // incorrectly inferred as [string, number]
let arr3 = arr as [string]; // incorrect conversion error

πŸ™ Actual behavior

See the comments in code above. What the TypeScript compiler infers is different from the actual runtime behavior.
It's worth noting that the return value of the call to splice() is correctly inferred as (string | number)[].

πŸ™‚ Expected behavior

Either calling arr.splice(1) should be an error (due to calling splice on a tuple), or the type of arr should be different after calling arr.splice(1).

@MartinJohns
Copy link
Contributor

MartinJohns commented Aug 7, 2021

Related, or perhaps even a duplicate of #40316. It refers to a different method, but the issue is the same.

@bbrk24
Copy link
Author

bbrk24 commented Aug 7, 2021

That's true, I didn't see that. The same problem exists with shift() as well.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Aug 10, 2021
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants