diff --git a/packages-private/dts-test/appUse.test-d.ts b/packages-private/dts-test/appUse.test-d.ts index 065f69568..21d702c9c 100644 --- a/packages-private/dts-test/appUse.test-d.ts +++ b/packages-private/dts-test/appUse.test-d.ts @@ -12,8 +12,11 @@ app.use(PluginWithoutType, 2) app.use(PluginWithoutType, { anything: 'goes' }, true) type PluginOptions = { + /** option1 */ option1?: string + /** option2 */ option2: number + /** option3 */ option3: boolean } @@ -25,6 +28,20 @@ const PluginWithObjectOptions = { }, } +const objectPluginOptional = { + install(app: App, options?: PluginOptions) {}, +} +app.use(objectPluginOptional) +app.use( + objectPluginOptional, + // Test JSDoc and `go to definition` for options + { + option1: 'foo', + option2: 1, + option3: true, + }, +) + for (const Plugin of [ PluginWithObjectOptions, PluginWithObjectOptions.install, @@ -92,7 +109,27 @@ const PluginTyped: Plugin = (app, options) => {} // @ts-expect-error: needs options app.use(PluginTyped) -app.use(PluginTyped, { option2: 2, option3: true }) +app.use( + PluginTyped, + // Test autocomplete for options + { + option1: '', + option2: 2, + option3: true, + }, +) + +const functionPluginOptional = (app: App, options?: PluginOptions) => {} +app.use(functionPluginOptional) +app.use(functionPluginOptional, { option2: 2, option3: true }) + +// type optional params +const functionPluginOptional2: Plugin<[options?: PluginOptions]> = ( + app, + options, +) => {} +app.use(functionPluginOptional2) +app.use(functionPluginOptional2, { option2: 2, option3: true }) // vuetify usage const key: string = '' diff --git a/packages/runtime-core/src/apiCreateApp.ts b/packages/runtime-core/src/apiCreateApp.ts index 3d53716de..748de866f 100644 --- a/packages/runtime-core/src/apiCreateApp.ts +++ b/packages/runtime-core/src/apiCreateApp.ts @@ -36,9 +36,9 @@ export interface App { use( plugin: Plugin, - ...options: Options + ...options: NoInfer ): this - use(plugin: Plugin, options: Options): this + use(plugin: Plugin, options: NoInfer): this mixin(mixin: ComponentOptions): this component(name: string): Component | undefined @@ -215,9 +215,11 @@ export type ObjectPlugin = { export type FunctionPlugin = PluginInstallFunction & Partial> -export type Plugin = - | FunctionPlugin - | ObjectPlugin +export type Plugin< + Options = any[], + // TODO: in next major Options extends unknown[] and remove P + P extends unknown[] = Options extends unknown[] ? Options : [Options], +> = FunctionPlugin

| ObjectPlugin

export function createAppContext(): AppContext { return {