nativewind: className type error
I created a new project with the expo blank typescript template. Then I followed the Quick start tutorial to implement tailwindcss-react-native.
It works perfectly but unfortunately I get an error with typescript error because of className.
No overload matches this call. #2769
Property 'className' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<View> & Readonly<ViewProps>'. #2772
I use VSCode
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 11
- Comments: 35 (1 by maintainers)
In my case, I’ve created
app.d.tsand added/// <reference types="nativewind/types" />but I still get typescript error because of className. So, i change the file nameapp.d.tstomy-app.d.tsand it works.@binajmen that worked like a charm
tl;dr - create a
my-app.d.tsand add the below snippet:I have just fixed it.
I had to put the
app.d.tsfile into mysrcfolderIf someone is passing by, last recommendation is here: https://www.nativewind.dev/getting-started/typescript
Hi @j3sch, create a new
src/tailwindcss-react-native.d.tsand pasteimport "tailwindcss-react-native/types.d";. See link from docsDon’t forget to restart your editor. In my case, until I restarted my VScode, the redline was still showing up after adding
app.d.tsIf you are using Neovim, what helped is creating a file (eg.
src/nativewind.d.ts) and pasting this line.No solution here worked for me (Expo w/ typescript mobile app), I finally found out that adding the type in the tsconfig.json works :
Rembember to include app.d.ts to tsconfig.json
Had the same issue in a turborepo/yarn workspace setup and the errors would not shift regardless of whichever variation of location + types definition I tried. Eventually realised the workspace hoisted the nativewind module up into the root directory rather than my React Native app. Excluding it from hoisting so it was colocated with the apps node modules finally sorted this out for me.
this indeed is what i forget to do
Thank you so much!!! this approach works for me!
I named mine app.d.ts and it didn’t work but, my-app.d.ts worked or any other name
None of the above will solve my problem
Here’s my solution
tsconfig.json
This one was a good old head scratcher… In my pnpm workspace adding “nativewind/types” to my base tsconfig worked fine for my sub-packages but it didn’t work for my main expo app.
To get the expo app to work as well, I needed to update the react-native path in the expo directory’s tsconfig file:
Hints working nicely (including Tailwind).
Hope this helps somebody!
For those who are still facing this issue, create a new
app.d.tsfile and add a triple-slash directive referencing the types./// <reference types="nativewind/types" />Reference: https://www.nativewind.dev/getting-started/typescript
Thank you very much for this, this worked for me too.
Does anyone know why app.d.ts stopped working? My code worked perfectly using app.d.ts until last week, and now naming the file my-app.d.ts, seems to make it work normally.
My team was getting this error because we were passing through all props to a Child Component.
We were able to resolve it when we extended the original Child Components Props using
React.ComponentProps<typeof Svg>For some reason typescript to work at all, and the tailwind style does apply correctly
root tsconfig.json
tsconfig.json
my-app.d.ts
and error is still
Perfect, thank you very much