Multiple non-null assertion operators (!
s) are redundant, and may confuse the reader.
Moreover, foo?.bar
should always be preferred over foo!?.bar
.
const foo: { bar: number } | null = null;
const bar = foo!!!.bar;
function foo(bar: number | undefined) {
const bar: number = bar!!!;
}
function foo(bar?: { n: number }) {
return bar!?.n;
}
const foo: { bar: number } | null = null;
const bar = foo!.bar;
function foo(bar: number | undefined) {
const bar: number = bar!;
}
function foo(bar?: { n: number }) {
return bar?.n;
}