element-plus/packages/utils/with-install.ts
jeremywu 3138dea797
fix(components): sub components no install issue (#3615)
- Add noop install for all sub components for supress the warning
2021-09-24 19:11:56 +08:00

35 lines
847 B
TypeScript

import { NOOP } from '@vue/shared'
import type { SFCWithInstall } from './types'
export const withInstall = <T, E extends Record<string, any>>(
main: T,
extra?: E
) => {
;(main as SFCWithInstall<T>).install = (app): void => {
for (const comp of [main, ...Object.values(extra ?? {})]) {
app.component(comp.name, comp)
}
}
if (extra) {
for (const [key, comp] of Object.entries(extra)) {
;(main as any)[key] = comp
}
}
return main as SFCWithInstall<T> & E
}
export const withInstallFunction = <T>(fn: T, name: string) => {
;(fn as SFCWithInstall<T>).install = (app) => {
app.config.globalProperties[name] = fn
}
return fn as SFCWithInstall<T>
}
export const withNoopInstall = <T>(component: T) => {
;(component as SFCWithInstall<T>).install = NOOP
return component as SFCWithInstall<T>
}