Closed
Description
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."