-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Tuple should be readonly by default #40316
Comments
Note that something like this was previously declined in #6325. I don't think it should be const x: [number, string] = [1, "hello"];
x[0]++; // should be fine
x[1] += " there"; // should be fine Instead, you'd probably just want to omit methods that can violate tuple constraints like (Aside: it's fun to think about which tuple types could still allow which methods safely... perhaps But I imagine that any form of this would be a big breaking change, right? Lots of code has |
Merging in additional issue: This should apply to all mutating methods ( |
Any tuples can mutate, this entails incorrect typing
TypeScript Version: 4.1.0-dev.20200828
Search Terms:
"readonly tuple"
"immutable tuple"
Code
Expected behavior:
Actual behavior:
Playground Link: https://www.typescriptlang.org/play?ts=4.1.0-dev.20200828#code/MYewdgzgLgBApgDwIYFsAOAbOBlEAnKALhgG0wBXFAIzjwBoZo8BLMAcwF0YBeUgJgYByAIyCOAbgBQkxKkw58UAHQRFACgCUUmcnRZcBGAHojMACoBPNHGJlKNeoygt2HBgCU4SDJeu2mrGwMFNS0HNKgkLCyejiYzMA2pCEODAGuPPxCohLSMfLY8YkqRXBqAAwMwlp5ugWlxqa+SXahjumcHl4+Vi0d4dKSQA
Related Issues:
The text was updated successfully, but these errors were encountered: