chore: fix type (#2516)
This commit is contained in:
parent
d3ec7a58ad
commit
92cc603680
|
|
@ -1,5 +1,5 @@
|
||||||
import type { RouteLocationNormalized, RouteRecordNormalized } from 'vue-router';
|
import type { RouteLocationNormalized, RouteRecordNormalized } from 'vue-router';
|
||||||
import type { App, Plugin } from 'vue';
|
import type { App, Component } from 'vue';
|
||||||
|
|
||||||
import { unref } from 'vue';
|
import { unref } from 'vue';
|
||||||
import { isObject } from '/@/utils/is';
|
import { isObject } from '/@/utils/is';
|
||||||
|
|
@ -57,7 +57,7 @@ export function openWindow(
|
||||||
}
|
}
|
||||||
|
|
||||||
// dynamic use hook props
|
// dynamic use hook props
|
||||||
export function getDynamicProps<T, U>(props: T): Partial<U> {
|
export function getDynamicProps<T extends Record<string, unknown>, U>(props: T): Partial<U> {
|
||||||
const ret: Recordable = {};
|
const ret: Recordable = {};
|
||||||
|
|
||||||
Object.keys(props).map((key) => {
|
Object.keys(props).map((key) => {
|
||||||
|
|
@ -82,13 +82,29 @@ export function getRawRoute(route: RouteLocationNormalized): RouteLocationNormal
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const withInstall = <T>(component: T, alias?: string) => {
|
// https://github.com/vant-ui/vant/issues/8302
|
||||||
const comp = component as any;
|
type EventShim = {
|
||||||
comp.install = (app: App) => {
|
new (...args: any[]): {
|
||||||
app.component(comp.name || comp.displayName, component);
|
$props: {
|
||||||
|
onClick?: (...args: any[]) => void;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export type WithInstall<T> = T & {
|
||||||
|
install(app: App): void;
|
||||||
|
} & EventShim;
|
||||||
|
|
||||||
|
export type CustomComponent = Component & { displayName?: string };
|
||||||
|
|
||||||
|
export const withInstall = <T extends CustomComponent>(component: T, alias?: string) => {
|
||||||
|
(component as Record<string, unknown>).install = (app: App) => {
|
||||||
|
const compName = component.name || component.displayName;
|
||||||
|
if (!compName) return;
|
||||||
|
app.component(compName, component);
|
||||||
if (alias) {
|
if (alias) {
|
||||||
app.config.globalProperties[alias] = component;
|
app.config.globalProperties[alias] = component;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return component as T & Plugin;
|
return component as WithInstall<T>;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue