不允许多余的非空断言。
interface BarType1 {
bar: number;
}
function getFoo(): BarType1 | null {
return null;
}
const foo: BarType1 | null = getFoo();
export const bar1: number | undefined = foo?.bar;
export function foo1(bar: number | undefined): void {
const newBar: number = bar ?? Number.MAX_VALUE;
console.info(`${newBar}`);
} interface BarType1 {
bar: number;
}
const foo1: BarType1 | null = null;
export const bar1 = foo1!!!.bar;
export function foo2(bar: number | undefined) {
const newBar: number = bar!!!;
console.info(`${newBar}`);
}
interface BarType2 {
n: number;
}
export function foo(bar?: BarType2) {
return bar!?.n;
}