본문 바로가기

'new' expression, whose target lacks a construct signature, implicitly has an 'any' type.ts(7009) 본문

Error

'new' expression, whose target lacks a construct signature, implicitly has an 'any' type.ts(7009)

개발자로 거듭나기 2023. 12. 8. 13:27
반응형

'new' expression, whose target lacks a construct signature, implicitly has an 'any' type.ts(7009)

상황

  • new 키워드를 사용해서 Image 객체를 만들려고 했더니..
  • 'new' expression, whose target lacks a construct signature, implicitly has an 'any' type.ts(7009) 라는 typescript 오류

해결

  • 우선 원인은 찾아보니, Image가 생성자 함수로 만들어져 있기 때문인 것 같습니다.
export default function Image({ src, sizes, unoptimized, priority, loading, lazyBoundary, className, quality, width, height, objectFit, objectPosition, onLoadingComplete, loader, placeholder, blurDataURL, ...all }: ImageProps): JSX.Element;
  • 해결법으로는
    • class 문법을 사용해서 constructor를 지정해주거나
    • any를 이용해 오류를 탈출 할 수 있습니다.
  • 우선 저 function 선언을 수정해 줄 수는 없으니 다음과같이 에러를 해결했습니다.
const image = new (Image as any)();
반응형
Comments