Skip to content

Definite assignment assertion doesn't work on object-short hand syntax #23118

Closed
@tinganho

Description

@tinganho

TypeScript Version: 2.7.0-dev.201xxxxx

Search Terms:
definite assignment assertion object shorthand

Code

interface A {
    a: string;
}

let As: A[] = [];
let a: string | undefined = 'ff';

function f() {
    As.push({ a! }); // Error
}

Expected behavior:
No error

Actual behavior:

Argument of type '{ a: boolean; }' is not assignable to parameter of type 'A'.
  Types of property 'a' are incompatible.
    Type 'boolean' is not assignable to type 'string'.

Playground Link:
http://www.typescriptlang.org/play/#src=interface%20A%20%7B%0A%20%20%20%20a%3A%20string%3B%0A%7D%0A%0Alet%20As%3A%20A%5B%5D%20%3D%20%5B%5D%3B%0Alet%20a%3A%20string%20%7C%20undefined%20%3D%20'ff'%3B%0A%0Afunction%20f()%20%7B%0A%20%20%20%20As.push(%7B%20a!%20%7D)%3B%20%2F%2F%20Error%0A%7D

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions