Version 3.1.1 of Vue now allows the App.use()
function to accept any type of argument, which appears to prevent enhancing its type declaration. In other words, attempting to augment the module does not overwrite the original App.use()
function (potentially because the use of any
supersedes MyPluginOptions
):
declare module '@vue/runtime-core' {
interface App {
use(plugin: MyPlugin, ...options: MyPluginOptions[]): this;
}
}
The only current solution seems to be directly modifying
node_modules/@vue/runtime-core/dist/runtime-core.d.ts
file by adding a generic to
Plugin_2
and
PluginInstallFunction
to allow typing the
options
argument:
declare type Plugin_2<Option = any> = PluginInstallFunction<Option> & {
install?: PluginInstallFunction<Option>;
} | {
install: PluginInstallFunction<Option>;
};
export { Plugin_2 as Plugin }
declare type PluginInstallFunction<Option> = (app: App, ...options: Option[]) => any;
After that, replace the current App.use()
with:
export declare interface App<HostElement = any> {
use<Option>(plugin: Plugin_2<Option>, ...options: Option[]): this;
}
demo
I have also submitted a pull request to vue-next
. If it is accepted, module augmentation will no longer be necessary, as the type of options
will be inferred automatically.