Skip to content

Non-null assertion type operator ! #14366

Closed
@YosubShin

Description

@YosubShin

TypeScript Version: 2.2.1

Code

interface Foo {
    bar: {
        baz: number;
    } | null;
}

type Baz = Foo["bar"]["baz"];  // This doesn't compile with the error: "Property 'baz' does not exist on type '{ baz: number; } | null'."
let x: Baz = 0;

Expected behavior:
I would expect there to be a way to specify bar is non-null, such as Foo["bar!"].

Actual behavior:
The code doesn't compile with the following error message:
"Property 'baz' does not exist on type '{ baz: number; } | null'."

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions