type Field = {test: {more: number} | null}
let fields: Field[] = [{test: {more: 55}}]
无论类型保护如何,Transpiler 都会抛出错误:
if (fields[0].test) {
fields[0].test.more = 55 // object is possibly null
}
这里没有错误:
function f(field: Field) {
if (field.test) field.test.more = 15 // no error
}