JSX issues in template #592
-
This discussion is a summary of related issues.
JSX is the only way to support normal component and functional component both with generic.
Template type-check (by JSX) depend to JSX namespace definition from If
Unfortunately, still has no found a suitable solution on the volar side. But you can setup tsconfig to avoid this problem on project side.
// tsconfig.json
{
"compilerOptions": {
// ...
"types": [
"vite/client", // if using vite
// ...
]
}
}
// tsconfig.json
{
// ...
"exclude": ["**/*.stories.ts"]
} This is the current situation, and there may be better solutions in the future. If you can’t solve it, or if you encounter other situations and have some experience in solving it, please share it here. |
Beta Was this translation helpful? Give feedback.
Replies: 25 comments 83 replies
-
Struggled a lot on this issue today. Thanks for posting. Current (the whole subdir uses tsconfig.json)
Desired (the needed tsconfig is used depending on the extensions)
This is easy to configure in the build tools, but not IDE (at least couldn't find it) |
Beta Was this translation helpful? Give feedback.
-
Hello i made a vue3 storybook setup but i am failing on this also. Even if i exclude all files in tsconfig that contain imports from storybook it's still using JSX react typings in vscode. Am i doing something wrong implementing the workaround? https://github.com/samydoesit/vue3-library-starter-vite-storybook tsconfig looks like this: {
"compilerOptions": {
"target": "esnext",
"useDefineForClassFields": true,
"module": "esnext",
"allowJs": true,
"moduleResolution": "node",
"strict": true,
"sourceMap": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"lib": ["esnext", "dom"],
"types": ["vite/client", "node"],
"baseUrl": "./",
"paths": {
"@/*": ["src/*"],
"#/*": ["types/*"]
},
"outDir": "dist/"
},
"exclude": [
"node_modules",
".storybook/**/*.js",
".storybook/**/*.ts",
"**/*.stories.ts",
"stories/**/*.js",
"stories/**/*.ts",
],
"include": [
"src/**/*.js",
"src/**/*.ts",
"src/**/*.d.ts",
"src/**/*.vue"
]
}
|
Beta Was this translation helpful? Give feedback.
-
In case it might help somebody: besides storybook, also the apollo graphql library can conflict. I had an import for ApolloClient and createHttpLink that my IDE made for me: // wrong: will lead to type conflicts with react
import { ApolloClient, createHttpLink } from "@apollo/client"; fortunately the fix in my case was easy: just import it from core: import { ApolloClient, createHttpLink } from "@apollo/client/core"; I will add some context, so this page can more easily be found thru search engines:
|
Beta Was this translation helpful? Give feedback.
-
Here is another temporary solution. {
"resolutions": {
"@types/react": "https://registry.yarnpkg.com/@favware/skip-dependency/-/skip-dependency-1.1.1.tgz"
}
} This will replace |
Beta Was this translation helpful? Give feedback.
-
this can solve the "class" attribute problem |
Beta Was this translation helpful? Give feedback.
-
I tried excluding the *.stories.ts from tsconfig.json but now I'm facing another problem: Vue component imports aren't being recognized. Has anyone faced this? |
Beta Was this translation helpful? Give feedback.
-
Hi,
vscode reload and fixed. |
Beta Was this translation helpful? Give feedback.
-
Been trying figure this out in my project and ended up finding out one of my dependencies was pulling in preact causing the issue. Not sure how to resolve the issue besides removing the dependency itself. I am in a position of migrating to vue3 and am going to drop this package anyway just have not gotten around to cleaning up package.json. The specific package was @fullcalendar/vue the below SS was the result of |
Beta Was this translation helpful? Give feedback.
-
Don't blame me. But this worked without modyfing create mkdir -p stub/types__react create a touch stub/types__react/package.json add this content to it {
"name": "@types/react",
"version": "0.0.0"
} create a touch stub/types__react/index.d.ts add an empty export, and the discussion URL for future references // https://github.com/johnsoncodehk/volar/discussions/592
export {} explicitly install @types/react from there npm i -D @types/react@file:stub/types__react In "@types/react": "file:stub/types__react", npm ls @types/react
[email protected] /Users/iamandrewluca/Projects/my-project
├─┬ @nuxtjs/[email protected]
│ └─┬ @storybook/[email protected]
│ └─┬ @storybook/[email protected]
│ └─┬ @storybook/[email protected]
│ └─┬ @types/[email protected]
│ └── @types/react@ deduped -> ./stub/types__react
└── @types/react@ -> ./stub/types__react |
Beta Was this translation helpful? Give feedback.
-
I solved it, add a scripts to package.json. "scripts": {
"postinstall": "rm -rf ./node_modules/@types/react"
} Then run |
Beta Was this translation helpful? Give feedback.
-
Reference to @iamandrewluca's solution, you can also do a similar thing in tsconfig.json instead of in package.json. (Just choose the way you want)
// stub/types__react/index.d.ts
export { }
// tsconfig.json
{
"compilerOptions": {
// ...
"types": [
// whitelist to include modules type from node_modules/@types
],
"paths": {
"react": ["./stub/types__react"]
}
},
} |
Beta Was this translation helpful? Give feedback.
-
I'm working on a Vue 3 based project that uses FullCalendar.js, and this is what worked for me: FullCalendar depends on preact, which includes a JSX namespace definition in its src/jsx.d.ts file. I set up a postinstall script in my package.json to remove that file:
Then, I deleted /node_modules/preact and ran "npm install" again to apply this change. After that, I added I don't love that this solution skips checking all declaration files, so if anyone knows of a better solution please let me know! |
Beta Was this translation helpful? Give feedback.
-
The problem is still there, any ideas? |
Beta Was this translation helpful? Give feedback.
-
The following workaround worked for me.
You may need to install react, or update your tsconfig.json with skipLibCheck = true, as in {
"compilerOptions": {
// ...
"skipLibCheck": true,
},
// ...
} Workaround in the import { AriaAttributes, DOMAttributes } from 'react' // not needed if skipLibCheck = true
declare module 'react' {
interface HTMLAttributes<T> extends AriaAttributes, DOMAttributes<T> {
// extends React's HTMLAttributes
class?: string
}
} Good luck! |
Beta Was this translation helpful? Give feedback.
-
This work for me with
{
"typeRoots": ["./types", "node_modules/@types"]
}
{
"paths": {
"react": ["types/react/index.d.ts"]
}
} Missing any step, or |
Beta Was this translation helpful? Give feedback.
-
I hope this PR will solve completely this problem |
Beta Was this translation helpful? Give feedback.
-
After v1.0.0-alpha.0, template is generate to regular ts code by default, so we don't have this problem by default. But generic props type will not working with this. To generate JSX template for support generic types, you need to config [Update] See #592 (comment) |
Beta Was this translation helpful? Give feedback.
-
There's a fix which is ready created by @iamandrewluca, I asked to cherry pick it to the current major version so we won't need to wait and upgrade another major. |
Beta Was this translation helpful? Give feedback.
-
thanks guy your ads is work |
Beta Was this translation helpful? Give feedback.
-
Opened a discussion to remove react types as a transitive dependency that breaks Volar |
Beta Was this translation helpful? Give feedback.
-
Anyone else currently experiencing this bug? I still have this bug Adding the following to tsconfig.json results in an error in the stories.ts file {
"compilerOptions": {
"types": [
"vite/client",
//...
]
},
"exclude": ["**/*.stories.ts"]
} |
Beta Was this translation helpful? Give feedback.
-
I have the same issue as @zestlee1106 . |
Beta Was this translation helpful? Give feedback.
-
Close as we have removed |
Beta Was this translation helpful? Give feedback.
-
I couldn't get any of the answers here to work, but what finally worked for me was to just add this to my compilerOptions in tsconfig.json: {
"paths": {
"react": [ "" ]
}
} My hope was that it would cause any attempts to load react types to fail and that seems to be what's happened. You will need to use a different tsconfig file to run storybook files, though. I did have mild success with making the |
Beta Was this translation helpful? Give feedback.
Close as we have removed
jsxTemplates
option in #2677 and don't have this problem anymore, you can update to v1.5.0 pre-release to try it.