core
core copied to clipboard
types(runtime-core): enable plugin option types
This enables type inference for:
- The
options
arg of a plugin'sinstall
function - The options passed to
createApp().use()
/**
* Plugin
*/
type PluginAOptionType = {
option1?: string;
option2: number;
option3: boolean;
}
const PluginA = {
install(app: App, ...options: PluginAOptionType[]) {
}
}
const PluginB = {
install(app: App) {
}
}
/**
* Main
*/
createApp({})
.use(PluginA, { option3: true }) // β option2 (required) missing
.use(PluginA, {}) // β option2 and option3 (required) missing
.use(PluginA) // β
.use(PluginA, { option2: 1, option3: true }) // β
.use(PluginA, { option1: 'foo', option2: 1, option3: true }) // β
.use(PluginB) // β
.use(PluginB, {}) // β unexpected plugin option
Thank you but there are already a few open PRs for this: https://github.com/vuejs/vue-next/pull/2758 https://github.com/vuejs/vue-next/pull/2589
@posva Oh, I missed those PRs. However, they appear to be outdated, as they no longer compile. Plus, I believe they'll introduce a breaking change for users. I'll comment in a moment.
@tony19 Can you help resolve the conflicts? Thanks
@antfu Done. Thanks!
@posva I agree, and the current code already allows that π
You were right! but it also should be stricter π Iβm reviewing on the phone so I canβt do much code but I will give it a proper review with help later