Skip to content

Long tuples lose appropriate type information #11924

Closed
@jocull

Description

@jocull

TypeScript Version:
2.0.3 / nightly (2.1.0-dev.201xxxxx)

Limit is seemingly even lower in 1.8.9, with type information loss after the tuple is 6 or more elements wide.

Code

// A *self-contained* demonstration of the problem follows...
Promise.all([
    Promise.resolve(1),
    Promise.resolve(''),
    Promise.resolve(new Date()),
]).then(results => {
    let [
        a, // Number
        b, // String
        c, // Date - Everything is ok!
    ] = results;
});

Promise.all([
    Promise.resolve(1),
    Promise.resolve(''),
    Promise.resolve(new Date()),
    Promise.resolve({}),
    Promise.resolve({ hi: 'hello' }),
    Promise.resolve([]),
    Promise.resolve(null as string),
    Promise.resolve(1),
    Promise.resolve(''),
    Promise.resolve(new Date()),
    Promise.resolve({}), // Length == 11
]).then(results => {
    let [
        a, // Everything is {} now?
        b,
        c,
        d,
        e,
        f,
        g, 
        h,
        i,
        j,
        k, // << -- Error!
           // "Tuple with length 10 cannot be assigned to tuple with length 11"?
    ] = results;
});

Code on the playground.

Expected behavior:
Tuple should be destructured with the appropriate types.

Actual behavior:
Types are lost after a seemingly arbitrary tuple limit. Actual tuple length is not understood by the compiler.

Workaround:
Break work up into smaller tuples below the limit and assemble them after. This will preserve type information.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ExternalRelates to another program, environment, or user action which we cannot control.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions