Skip to content

Readonly open-ended tuples have writable length property #47260

Closed
@ASDFGerte

Description

@ASDFGerte

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions