Skip to content

Suggestion: Let null assertion (!) operator block "used before assigned" errors #11463

Closed
@ghost

Description

TypeScript Version: nightly (2.1.0-dev.20161008)

Code

(Compile with --strictNullChecks)

let n: number
doit(() => {
    n = 0
})
n! + 1

function doit(action) { action() }

Expected behavior:

No error

Actual behavior:

a.ts(5,1): error TS2454: Variable 'n' is used before being assigned.

The problem is fixed by using let n: number | undefined, but it's not obvious that that's the solution, and it would be intuitive for the ! operator to work in this situation.

Aside: I don't see the ! operator documented in the handbook.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedA PR has been merged for this issueHelp WantedYou can do thisSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions