You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

26 lines
832 B

import type { App } from 'vue'
import type { SFCWithInstall } from './types'
import { NOOP } from './types'
export const withNoopInstall = <T>(component: T) => {
;(component as SFCWithInstall<T>).install = NOOP
return component as SFCWithInstall<T>
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const withInstall = <T, E extends Record<string, any>>(main: T, extra?: E) => {
;(main as SFCWithInstall<T>).install = (app: 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)) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(main as any)[key] = comp
}
}
return main as SFCWithInstall<T> & E
}