Skip to content

unbounded type is not strict #40235

Description

@royling

TypeScript Version: 4.0.2

Search Terms: unbounded

Code

type Strings = [string, string];
type Numbers = number[];

type Unbounded = [...Strings, ...Numbers, boolean];
//   ^?

const data: Unbounded = ['a', 'b', false, false]; // <-- No error?
console.log(data);

Expected behavior:
The above Unbounded type should allow only the last element in the tuple as boolean, other elements in range [2, -2] if available should be numbers only.

Actual behavior:
[...number[], boolean] is now handled as <number | boolean>[]

Playground Link:
https://www.typescriptlang.org/play?#code/C4TwDgpgBAysBOBLAdgcwM5QLxQNroRVQBooCk0BdAbgChRIoA5AVwFsAjCeTHZdrvFw1a9cNACqyDgHsWyACYQF2PADoNcChlIa1rTt3SlZMgDYQAhshEB6W1EcA9APyiAxjOQEoCy8EsALigpWXklFRxcAHJLaNJojnioADNLM3QIUjSMiBFPb3MINTMZVAAKPwCASmogA

Related Issues:
No.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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