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

Readonly open-ended tuples have writable length property #47260

Closed
ASDFGerte opened this issue Dec 28, 2021 · 1 comment · Fixed by #47717
Closed

Readonly open-ended tuples have writable length property #47260

ASDFGerte opened this issue Dec 28, 2021 · 1 comment · Fixed by #47717
Labels
Bug A bug in TypeScript Help Wanted You can do this

Comments

@ASDFGerte
Copy link

Bug Report

In general, readonly tuples appear to not have a readonly length property.

type Test = Pick<[number], 'length'>;
//   ^?
// type Test = { length: 1; }
// no readonly modifier
declare const x: readonly [number?];
x.length = 0; // no error
declare const y: readonly [number, ...number[]];
y.length = 0; // no error
declare const z: readonly number[];
z.length = 0; // error, as expected

🔎 Search Terms

readonly tuple length property

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about common "Bugs" that aren't bugs

⏯ Playground Link

Playground link with relevant code

🙁 Actual behavior

A readonly tuple's length property is not readonly, and can as such we overwritten.

🙂 Expected behavior

A readonly tuple's length property should be readonly, similar to arrays, and disallow writes.

@jcalz
Copy link
Contributor

jcalz commented Dec 31, 2021

(Linking to https://stackoverflow.com/questions/70501410/why-is-a-readonly-tuples-length-writable where this presumably came from)

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jan 11, 2022
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jan 11, 2022
@RyanCavanaugh RyanCavanaugh added the Help Wanted You can do this label Jan 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants