아래 코드에서 두 번째 가드는 루프 ab.cv
내부의 비 -nullity를 주장 할 수 없으며 forEach
로컬 동일한 가드의 주석 처리를 제거하면 작동합니다. 왜 그래야만하지?
type B = {|
bv: B[],
cv: ?number
|}
let ab: B = {bv: [], cv: 1}
if (ab.cv) { // First guard
const a = ab.cv + 1 // Works
}
var a2;
if (ab.cv) { // Second guard
ab.bv.forEach(b => {/*if (ab.cv) */a2 = ab.cv + 1}) // Doesn't work except if uncommented
// Cannot perform arithmetic operation because null or undefined [1] is not a number.
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다