Commit 92cc6036801085778dca58345a4c6a2b4c06f4ef

Authored by luocong2016
Committed by GitHub
1 parent d3ec7a58

chore: fix type (#2516)

Showing 1 changed file with 23 additions and 7 deletions
src/utils/index.ts
1 import type { RouteLocationNormalized, RouteRecordNormalized } from 'vue-router'; 1 import type { RouteLocationNormalized, RouteRecordNormalized } from 'vue-router';
2 -import type { App, Plugin } from 'vue'; 2 +import type { App, Component } from 'vue';
3 3
4 import { unref } from 'vue'; 4 import { unref } from 'vue';
5 import { isObject } from '/@/utils/is'; 5 import { isObject } from '/@/utils/is';
@@ -57,7 +57,7 @@ export function openWindow( @@ -57,7 +57,7 @@ export function openWindow(
57 } 57 }
58 58
59 // dynamic use hook props 59 // dynamic use hook props
60 -export function getDynamicProps<T, U>(props: T): Partial<U> { 60 +export function getDynamicProps<T extends Record<string, unknown>, U>(props: T): Partial<U> {
61 const ret: Recordable = {}; 61 const ret: Recordable = {};
62 62
63 Object.keys(props).map((key) => { 63 Object.keys(props).map((key) => {
@@ -82,13 +82,29 @@ export function getRawRoute(route: RouteLocationNormalized): RouteLocationNormal @@ -82,13 +82,29 @@ export function getRawRoute(route: RouteLocationNormalized): RouteLocationNormal
82 }; 82 };
83 } 83 }
84 84
85 -export const withInstall = <T>(component: T, alias?: string) => {  
86 - const comp = component as any;  
87 - comp.install = (app: App) => {  
88 - app.component(comp.name || comp.displayName, component); 85 +// https://github.com/vant-ui/vant/issues/8302
  86 +type EventShim = {
  87 + new (...args: any[]): {
  88 + $props: {
  89 + onClick?: (...args: any[]) => void;
  90 + };
  91 + };
  92 +};
  93 +
  94 +export type WithInstall<T> = T & {
  95 + install(app: App): void;
  96 +} & EventShim;
  97 +
  98 +export type CustomComponent = Component & { displayName?: string };
  99 +
  100 +export const withInstall = <T extends CustomComponent>(component: T, alias?: string) => {
  101 + (component as Record<string, unknown>).install = (app: App) => {
  102 + const compName = component.name || component.displayName;
  103 + if (!compName) return;
  104 + app.component(compName, component);
89 if (alias) { 105 if (alias) {
90 app.config.globalProperties[alias] = component; 106 app.config.globalProperties[alias] = component;
91 } 107 }
92 }; 108 };
93 - return component as T & Plugin; 109 + return component as WithInstall<T>;
94 }; 110 };