1

I'm working on a React Native project using NativeWind for Tailwind CSS support. I've followed the NativeWind documentation for TypeScript integration, but I'm still encountering a TypeScript error related to the className prop.

Error Message:

TS2769: No overload matches this call.
  Overload 1 of 2, '(props: ViewProps | Readonly<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.
    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>'

Project Setup:

React Native Version: 0.72.6 NativeWind Version: 2.0.11 TypeScript Version: 5.3.3 Expo SDK Version: 49.0.15 I have set up my tsconfig.json and app.d.ts as per the NativeWind documentation:

tsconfig.json:

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es5",
    "sourceMap": true,
    "plugins": [{ "name": "nativewind/typescript-plugin" }]
  },
  "exclude": ["node_modules"],
  "extends": ["expo/tsconfig.base", "@tsconfig/react-native/tsconfig.json"]
}

app.d.ts:

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

Attempted Solutions:

  • Reinstalled node modules and cleared cache.
  • Restarted the TypeScript server and development environment.
  • Checked for the correct version compatibility among NativeWind, React Native, TypeScript, and Expo.

Despite these efforts, the TypeScript error persists.

It appears to be an issue with TypeScript not recognizing nor the className nor the style prop added by NativeWind on React Native components. This prop is essential for using Tailwind CSS classes in the project.

Questions:

  • Has anyone else encountered this TypeScript error with NativeWind in a React Native project?
  • Are there additional steps or configurations required for TypeScript to recognize the className prop in React Native components when using NativeWind?
  • Could this be a version compatibility issue or a bug in one of the libraries?
3
  • I'm having this issue using 73.5 RN version with pnpm. All the solutions provided from the Stackoverflow, Github, and other articles are still not working
    – Jrey
    Commented Mar 10, 2024 at 4:42
  • Actually no, I gave up and work with good old CSS
    – A Mehmeto
    Commented Mar 11, 2024 at 6:41
  • regarding this one. I fixed it. I updated the tsconfig.json based on the needs. Thanks for the reply :)
    – Jrey
    Commented Mar 11, 2024 at 7:14

2 Answers 2

4

I came across the same problem few days ago, I just solved mine now.

Here is what you do: in your app folder in the expo (that is where you have the assets folder, constants, components e.t.c.) you make a a file named nativewind-env.d.ts.

Then, paste this line inside the file:

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

it should stop the error message your getting, make you to note the file structure, I will give an image of mine, as well as the code

This shows the code your supposed to paste

This shows the place where the nativewind-env.d.ts file you create is supposed to be

if my explanation is still not clear, I will refer you to the docs https://www.nativewind.dev/getting-started/typescript

2

I came across the same problem two weeks ago. Typescript is causing that error for some unknown reason.

Change app.d.ts file to another name like eg. myapp.d.ts and it should work.

This problem is also detailed on nativewind github repo.

https://github.com/marklawlor/nativewind/issues/77

Hope this helps

1
  • can confirm this worked for me Commented Feb 14, 2024 at 8:33

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.