core
core copied to clipboard
Make JSX typings an optional install as they conflict with React TSX
Version
3.0.0-beta.3
Reproduction link
https://github.com/elevatebart/vue-next-react-ts-conflict
Steps to reproduce
# Checkout the repo
git checkout https://github.com/elevatebart/vue-next-react-ts-conflict.git
# Install all modules
npm ci
# run tsc
npm start
The errors you see in the console are due to React and Vue TSX accepting different values.
What is expected?
When migrating from React to Vue, types should not fail without installing them.
What is actually happening?
it fails at compilation
JSX types could be made a separate package: @vue/jsx-types
.
This way, types would not systematically be installed.
Devs could install the runtime they need without the typings.
The transition would be easier.
I could see this problem be solved temporarily by resynchronizing the types of react and vue. I would see this alignment as a nightmare to maintain in the long term.
But are you going to use JSX/TSX in Vue, or are you going entirely with templates?
While this does make it compile, you still wouldn't be able to use Vue TSX until you completely remove React typings?
Agreed, and choose when to do this switch from React JSX to Vue JSX.
What do you suggest?
a bit of context
Vue-styleguidist uses React to render a style guide for VueJs components. Most of the code is in react though. Vue only comes in play in the preview. The reason being, same as for storybook, that the original product was written in react.
Should I rewrite it completely using Vue? Though there is a project started for that, I feel like I am letting my users down changing technology suddenly. Since all customizations of styleguidist was done in react before, it would be better to be able to at least choose when they switch.
Really looking forward to your opinion.
I could create a Pull Request to expose what I think could be useful.
@shilman, @Aaron-Pool Did you experience the same kind of issue implementing vue-next in storybook?
The main conflict seems to be about NativeElements
/ IntrinsicElements
.
Another solution might be to share the definition of the NativeElements
in a separate package, then have React and Vue typings depend on the same package.
This way, TSX conflicts will be avoided until one chooses to switch from react TSX to vue TSX.
@elevatebart we haven't yet implemented vue-next in storybook. you're in uncharted territory! 😄
@elevatebart Same here, the furthest I've gone is using jsx with the Vue 2.x composition-api plugin. Haven't started to explore the vue-next waters just yet.
Hello @DanielRosenwasser,
Does TypeScript have a solution to deal with JSX ambient types conflicting?
I tried using the "types":[]
trick without luck.
I tried using the paths: {}
trick to redirect retrieval of types to another object but since types are ambient there is still a conflict.
What solutions do you see?
Either vue or react not both. That is the same issue by use react and preact together.
Use storybook for your components doc.
@martinoppitz I do not understand. Do you mean that preact typings are different from react typings?
What do you suggest I do in a monorepo that has both react and Vuejs ?
React and VueJs are not in the same package in the above monorepo.
I think the ide does not differnce beetween the subfolder projects.
Thank you for this perspective ... because I believe/feel "mono repos are a other name for monoliths."
try to reduce the overhead by managing the independent packages ... a go back to move all in only one repo.
If you are disciplined, then you can also properly design/develop monoliths.
Thank you @martinoppitz,
I understand your disliking for monorepos. They can create monoliths that are long to clone and even longer to install.
In our case though, the vue-next monorepo could save our bacon. It allows easy extraction of a package in a PR. Once the PR is accepted, all 3 modified packages are delivered at once. No downtime when packages are incompatible or missing a library and e2e testing can continue without breaking.
Regarding JSX, can you expand a little what I should do? Are you implying that this is not an issue? Are you suggesting a maintainer should use one repository for React and one for Vue and they should never mix?
I would not expect The Progressive JavaScript Framework to force a complete rewrite of the code upon adoption if there is another solution.
@elevatebart just so you know I'm considering doing this, but still trying to figure out the best way to organize it with the upcoming Vue 3 JSX transform.
Thank you @yyx990803, this will help a lot. If you are looking for someone to bounce ideas with, ping me on VueLand. I'll be happy to show enthusiasm or constructive criticism.
Except for this hiccup, the migration to Vue 3 is bringing a lot of performance to docgen and styleguidist. I like it.
FYI, namespace JSX
can be renamed to avoid conflict (for example, VueJSX
).
And TypeScript uses VueJSX
instead of JSX
by putting this configuration into tsconfig.json
.
"jsxFactory": "VueJSX"
I create a vue project with vue-cli. the project has a dependency of package named B. B has a dependency with react types. for example:
import type { PropsWithChildren } from 'react';
then my project emit errors:
Type '{ children: Element[]; class: string; }' is not assignable to type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'. Property 'class' does not exist on type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'. Did you mean 'className'?ts(2322)
here is my code:
index.tsx
:
import { defineComponent, ref } from 'vue';
import style from './index.module.less';
export default defineComponent({
setup() {
const activeTab = ref('tab-one');
return () => (
<div
class={style.detail}
>
xxxx
</div>
)
},
});
I strive for solving this, what can I do with this situation?
remove the package which has a dependency with react library, the error disappear.
by the way. I organized my project with mono repo. which has react project and vue project.
I started getting these errors after installing storybook 3.6.10. My project's stack is vite + vue3 (typescript), while storybook is using webpack and is based on react, so I'm making a wild guess that by adding storybook, these errors started surfacing because of react dependencies.
Type '{ class: string; }' is not assignable to type 'DetailedHTMLProps<OlHTMLAttributes<HTMLOListElement>, HTMLOListElement>'.\n Property 'class' does not exist on type 'DetailedHTMLProps<OlHTMLAttributes<HTMLOListElement>, HTMLOListElement>'. Did you mean 'className'?"
@olemarius did you find more info on this?
I have a monorepo with one package depending on Vue and other on react. I use pnpm which does not hoists dependencies. Then I have a tsconfig.json for each package. Hence, no JSX conflicts.
But If I have to use Vue and react in same package/file, avoiding conflict is not possible.
I started getting these errors after installing storybook 3.6.10. My project's stack is vite + vue3 (typescript), while storybook is using webpack and is based on react, so I'm making a wild guess that by adding storybook, these errors started surfacing because of react dependencies.
Type '{ class: string; }' is not assignable to type 'DetailedHTMLProps<OlHTMLAttributes, HTMLOListElement>'.\n Property 'class' does not exist on type 'DetailedHTMLProps<OlHTMLAttributes, HTMLOListElement>'. Did you mean 'className'?"
@olemarius Did you find a way to resolve this I'm having the same problem with Vue and Storybook setup with vite + vue3?
I had the same problem
same problem @yyx990803
I have the same problem. I get
Type '{ class: string; }' is not assignable to type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'.
Property 'class' does not exist on type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'. Did you mean 'className'?
@olemarius did you resolve it?
Also check: https://github.com/eirslett/storybook-builder-vite and https://storybook.js.org/blog/storybook-for-vite/
Hi,
Try this in your tsconfig.json file
"exclude": [
"**/node_modules",
"**/dist",
// https://github.com/johnsoncodehk/volar/discussions/592
"**/*.stories.ts"
]
Thanks olemarius.
Adding this fixed it
// tsconfig.json
{
"compilerOptions": {
// ...
"types": [
"vite/client", // if using vite
// ...
]
}
}
For me latest @vue/runtime-dom
is also conflicting internally.
excluding **/*.stories.ts
and including vite/client
doesn't prevent @vue/runtime-dom
having conflict with @types/react
. I have no idea where VS Code's TS might grab the React types, but we have @storybook/vue
installed and some *.ts
storybook stories in the project.
I deleted the @storybook/testing-vue3": "^0.0.1
and the error stopped.
Removing node_modules/@storybook/testing-vue3/
had the same effect.
Having same issue, but because I have a react and vue package in packages
folder in a pnpm workspace, and it's by design
Svelte typings don't break though
Edit: It's resolved for me. Had to provide "preserveSymlinks" in tsconfig.json for rollup-plugin-dts
to work