Skip to content

Non-null assertion operator non working on properties #15796

@HolgerJeromin

Description

@HolgerJeromin

TypeScript Version: 2.3

Code

export interface Dictionary<T> {
    [index: string]: T | undefined;
}
const name = 'bar';
let foo: Dictionary<number> = {};
if (foo[name] === undefined) {
    foo[name] = 1;
} else {
    let numberOrUndef = foo[name];
    let numb = foo[name]!;
    foo[name]++;
}

last code line foo[name]++; is probably undefined. Ok, it is not, but no problem.
But i cannot override this with the Non-null assertion operator !

foo[name]!++; gives "The operand of an increment or decrement operator must be a variable or a property access."

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions