Skip to content

Types of property length are incompatible when extending tuple types. #20539

Closed
@andnp

Description

@andnp

TypeScript Version: typescript@2.7.0-dev.20171207

Code

type UnionizeTuple<T extends [any]> = T[number];
type a = ['hi', 'there']
type b = UnionizeTuple<a>

Expected behavior:

b === 'hi' | 'there'

Actual behavior:

Type '["hi", "there"]' does not satisfy the constraint '[any]'.
  Types of property 'length' are incompatible.
    Type '2' is not assignable to type '1'

This is working as expected in all previous versions of typescript. Updated to the latest typescript@next this morning and this broke. I see why this happened, by being smarter about how we process tuples we can know at compile time the length of a tuple. But because there are not variadic kinds, there is no other way to accomplish the above (or much more complicated examples as I am using elsewhere).

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions