Skip to content

deleting a prop doesn't invalidate the interface #13783

Closed
@donaldpipowitch

Description

@donaldpipowitch

TypeScript Version: 2.1? (Playground)

Code

interface Props {
    foo: string;
    bar: string;
}

const p: Props = {
    foo: 'hello',
    bar: 'world'
}

const say = (props: Props) => console.log(`${props.foo.length} ${props.bar.length}`);

say(p);

delete p.bar;
say(p); // works, but should throw

See here.

Expected behavior:

Don't compile, because we delete bar from p.

Actual behavior:

Compiles. Resulting in a runtime error: Uncaught TypeError: Cannot read property 'length' of undefined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Breaking ChangeWould introduce errors in existing codeFixedA PR has been merged for this issueSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions