본문 바로가기
Frontend/React

리액트 네이티브 + 타입스크립트에서 className 에러

by yerin.dev 2024. 6. 20.

문제 상황

 

 

React Native + TypeScript + Native Wind(TailwindCSS)를 사용해서 프로젝트를 하는 중 마주친 ts 에러!

 

 

No overload matches this call.
  Overload 1 of 2, '(props: ViewProps): View', gave the following error.
    Type '{ children: Element[]; className: string; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<View> & Readonly<ViewProps>'.
      Property 'className' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<View> & Readonly<ViewProps>'.
  Overload 2 of 2, '(props: ViewProps, context: any): View', gave the following error.

 

 

해결

프로젝트 루트 경로에 global.d.ts 파일을 만들고

 

/// <reference types="nativewind/types" />

 

 

를 써 넣어준다. /// 슬래시 세 개 까지 그대로!

 

 

 

출처

https://stackoverflow.com/questions/72909992/react-native-typescript-giving-me-an-ts-error-when-using-classname