if (mod && typeof (mod as any).ReactComponent === 'function')
mod && ...mod가 falsy (undefined, null, 0, '')가 아닐 때
typeof (mod as any).ReactComponent === 'function'mod 객체에 RacrComponent라는 프로퍼티가 있고, typeof(타입 확인하는)으로 그 타입이 'function'인지 확인 맞으면 true
const mod1 = { ReactComponent: () => {} }; // 함수
const mod2 = { ReactComponent: "hello" }; // 문자열
const mod3 = null;
if (mod1 && typeof mod1.ReactComponent === 'function') {
console.log('mod1 실행됨'); // 실행
}
if (mod2 && typeof mod2.ReactComponent === 'function') {
console.log('mod2 실행됨'); // 실행 안 됨
}
if (mod3 && typeof mod3.ReactComponent === 'function') {
console.log('mod3 실행됨'); // 실행 안 됨
}