Open
Description
According to Vue 3.4 docs, if I want to define a custom plugin, I need to create it like this:
// my-custom-plugin.ts
export default {
install: (app, options) => {
// do something here with app and options
}
}
Then, on main.ts
, I set app to use it:
import App from './App.vue'
import router from './router'
import customPlugin from './my-custom-plugin'
export const app = createApp(App)
app.use(router)
app.use(customPlugin)
And that was OK until I updated Vue to version 3.4.20. I was using 3.2.45 before.
Now, when I try to build the project with yarn build
(which uses vite build
too) it throws this error:
Argument of type '{ install: (app: App, options: any) => void; }' is not assignable to parameter of type 'Plugin<[]>'.
Type '{ install: (app: App, options: any) => void; }' is not assignable to type 'FunctionPlugin<[]>'.
After searching for type definitiions in node_modules/@vue/runtime-core/dist/runtime-core.d.ts
, I found out that, in order to Typescript doesn't claim any type errors, I must define my plugin as an ObjectPlugin type.
I did it this way:
import { ObjectPlugin } from 'node_modules/@vue/runtime-core/dist/runtime-core'
export default {
install: (app, options) => {
// stuff
},
} as ObjectPlugin
I can't use Plugin type because it says that Plugin type is deprecated
.
Is my fix correct? How can I contribute so the Vue docs has some notes regarding Typescript support?