Skip to content

Commit

Permalink
fix: vue2 TypeHelper 组件 事件方法类型提示
Browse files Browse the repository at this point in the history
vue2 TypeHelper 组件 事件方法类型提示
  • Loading branch information
hewx815 committed Sep 8, 2023
1 parent a88f32d commit cab8c89
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ export interface View {
hoverStayTime: number;
};

events: {
click: () => void;
};
events: object
}

/**
Expand Down
44 changes: 22 additions & 22 deletions for-vue2/src/packages/plugins/TypeHelper/utils.d.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import {
DefineComponent,
ComputedOptions,
MethodOptions,
ComponentOptionsMixin,
SlotsType,
ExtractDefaultPropTypes,
PropType,
} from '@vue/runtime-dom';

export type DefinePropsOptions<T> = {
[K in keyof T]: {
type: PropType<T[K]>;
default: T;
export type DefinePropsOptions<Props> = {
[K in keyof Props]: {
type: PropType<Props[K]>;
default: Props;
}
};

export type DefineComponentsHelper<T = { props: object; events: object; }, CommonProps = object, CommonEvents = object> = {
[K in keyof T]: DefineComponent<
DefinePropsOptions<T[K]['props'] & CommonProps>,
unknown,
unknown,
ComputedOptions,
MethodOptions,
ComponentOptionsMixin,
ComponentOptionsMixin,
T[K]['events'] & CommonEvents,
export type EmitsToEvents<Emits> = {
[K in keyof Emits as `on${Capitalize<K & string>}`]?: Emits[K];
};

export type DefineComponentsHelper<Components = { props: object; events: object; }, CommonProps = object, CommonEmits = object> = {
[K in keyof Components]: DefineComponent<
DefinePropsOptions<Components[K]['props'] & CommonProps>,
object,
object,
object,
object,
object,
object,
Components[K]['events'] & CommonEmits,
string,
unknown,
unknown,
ExtractDefaultPropTypes<DefinePropsOptions<T[K]['props'] & CommonProps>>,
SlotsType
object,
EmitsToEvents<Components[K]['events'] & CommonEmits>,
ExtractDefaultPropTypes<DefinePropsOptions<Components[K]['props'] & CommonProps>>,
object
>
};

0 comments on commit cab8c89

Please sign in to comment.