-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@vue/compat not working with Typescript #4330
Comments
I've also tried by adding the following in "paths": {
"vue/*": [
"@vue/compat/*"
]
} and "paths": {
"vue/*": [
"node_modules/@vue/compat/*"
]
} |
You need to use Maybe it's worth adding more info in the docs repo. If you think so, a PR would be welcome 🙂 |
But the default export doesn't seem to be properly typed with this. You can in fact do this in the prodived repo: import { Vue, CompatVue } from 'vue'
(Vue as unkown as CompatVue).config.productionTip = false Which would get rid of the error and instead shows helpful deprecation notes from the above type definition. but surely isn't the workflow we have in mind. I first thought it might be an issue with the shims in that repo, but changing them to vue 3 style shims didnt't solve the issue. I will reopen this as I think it should be possible to type the constructor properly. |
It indeed seems to be a problem with the constructor typing. That being said, the workaround does not seem to be working on my end: ERROR in src/main.ts:1:10
TS2305: Module '"../node_modules/vue/dist/vue"' has no exported member 'Vue'.
> 1 | import { Vue, VueCompat } from 'vue'
| ^^^
2 | import App from './App.vue'
3 |
4 | (Vue as unknown as VueCompat).config.productionTip = false
ERROR in src/main.ts:1:15
TS2305: Module '"../node_modules/vue/dist/vue"' has no exported member 'VueCompat'.
> 1 | import { Vue, VueCompat } from 'vue'
| ^^^^^^^^^
2 | import App from './App.vue'
3 |
4 | (Vue as unknown as VueCompat).config.productionTip = false |
...which is why I directly deleted my comment again, seems you were faster though. For one, the type is |
Ohh my bad! This workaround, though not ideal, does indeed work: import Vue, { CompatVue } from 'vue'
(Vue as unknown as CompatVue).config.productionTip = false |
Here's how to get the types working (add this in a declare module 'vue' {
import { CompatVue } from '@vue/runtime-dom'
const Vue: CompatVue
export default Vue
export * from '@vue/runtime-dom'
} Also added to docs |
Ohh great! Thanks! |
After I try this code, other members such as createApp do not exist. It is recommended to add
|
Version
3.2.2
Reproduction link
https://github.com/philippevezina/vue-compat-ts
Steps to reproduce
vue.config.js
as such:yarn serve
What is expected?
The project should run on Vue 3 with Typescript with Vue 2 code.
What is actually happening?
Many errors for things that should be supported by
@vue/compat
such as this one:The text was updated successfully, but these errors were encountered: