Skip to content

Bad null error in destructuring #14630

Closed
Closed
@ghost

Description

TypeScript Version: nightly (2.3.0-dev.20170313)

Code

interface A {
    foo?: { x: number };
    bar?: { y: number };
}

function f(a: A) {
    if (a.foo && a.bar) {
        const xx = a.foo.x; const yy = a.bar.y; // No error
        const { foo: { x }, bar: { y } } = a; // Error
    }
}

Expected behavior:

No errors.

Actual behavior:

a.ts(9,24): error TS2459: Type '{ x: number; } | undefined' has no property 'x' and no string index signature.
a.ts(9,36): error TS2459: Type '{ y: number; } | undefined' has no property 'y' and no string index signature.

May be related: #12620, #6784

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions