```type ExampleType { val1: string; val2: numb...
# 클럽-프론트엔드
u
Copy code
type ExampleType {
  val1: string;
  val2: number;
};

type TargetList = (ExampleType | null)[];

const targetList: TargetList = [{...}, {...}, ...];

const result = targetList.map(({ val1 }) => (...));
이런식으로 쓰려고 하는데
targetList.map
에서
val1
의 타입추론이 안되네요. 이런 경우엔
for
문 써서 빼내는 수밖에 없을까요?
h
Copy code
targetList.map(target => {
  if (target === null) return null;
  const { val1 } = target;
  // 여기서 map
})
👍 1
u
간단한거라면 optional chaning을 이용해서 target?.val1로도 가능할것 같아요.
u
이 경우가 최선이겠군요 감사합니다. 배열 메서드 추론안되는건 짜치는군요
h
null 있는 언어는 어쩔 수 없습니다. 싫으면 Option 모나드를 쓰시는것도 방법
저건 추론이 올바르게 된거고요
u
추론이 바르게 된 거라 더 힘들군요 ㅋㅋ 감사합니다