티스토리 뷰

에러 노트

[TS] No overload matches this call.

2021bong 2022. 11. 27. 22:38

스타일드 컴포넌트에 제네릭으로 Props도 정해줬는데 빨간줄이 떴다... 왜...?

// bgColor -> No overload matches this call.
const BandAd = ({ text, color }: BandAdProps) => {
  return <Container bgColor={color}>{text}</Container>;
};

...

const Container = styled.div<StyledBandAdProps>`
...
`

 

No overload matches this call.


이유

이 자리에 undefined가 들어 올 수 도 있는데 내가 string만 정해줘서 그런 것이었다. 메세지를 자세히 보니 중간에 Type 'undefined' is not assignable to type 'string'. 라고 하고 있었다.

// 에러
export interface StyledBandAdProps {
  bgColor: string;
}

// 수정
export interface StyledBandAdProps {
  bgColor: string | undefined;
}

 

참고

728x90
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함