Skip to content

Preserve constness of generics with tuple typesΒ #52007

@jfet97

Description

@jfet97

Bug Report

πŸ”Ž Search Terms

const modifier, generics, tuple types

πŸ•— Version & Regression Information

It shows up just in the nightly version because const modifiers for generics will be available from TS 5.0

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

declare function inners<const T extends readonly any[]>(...args: readonly [unknown, ...T, unknown]): T;

const test = inners(1,2,3,4,5);

πŸ™ Actual behavior

T is inferred as [number, number, number] instead of readonly [2,3,4]. There are other ways to write this function by avoiding tuple types at all, but it is a nice example to show that that the constness introduced by the const modifier seems to be lost when tuple types come into play, even with the readonly modifier.

πŸ™‚ Expected behavior

T inferred as readonly [2,3,4]

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions