Skip to content

Commit 4b95a29

Browse files
committed
fix: fix mixin infer
1 parent 90ee362 commit 4b95a29

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

types/options.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ export type ThisTypedComponentOptionsWithArrayProps<
106106
Record<PropNames, any>,
107107
SetupBindings
108108
> & {
109-
mixins?: Mixin[]
110-
extends?: Extends
109+
mixins?: (Mixin | typeof Vue)[]
110+
extends?: Extends | typeof Vue
111111
} & ThisType<
112112
CombinedVueInstance<
113113
V,
@@ -143,8 +143,8 @@ export type ThisTypedComponentOptionsWithRecordProps<
143143
Props,
144144
SetupBindings
145145
> & {
146-
mixins?: Mixin[]
147-
extends?: Extends
146+
mixins?: (Mixin | typeof Vue)[]
147+
extends?: Extends | typeof Vue
148148
} & ThisType<
149149
CombinedVueInstance<
150150
V,

types/vue.d.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ export interface Vue<
100100

101101
type ComponentMixin = ComponentOptions<any, any, any, any, any>
102102

103+
// IntersectionMixin cannot infer `data` from ComponentOptions<...>
104+
type PrepareMixinData<M extends ComponentMixin, D = Required<M>['data']> = {
105+
[K in keyof M]: K extends 'data'
106+
? D extends (...args: any) => infer R
107+
? (this: any) => R
108+
: (this: any) => D
109+
: M[K]
110+
}
103111
export type CombinedVueInstance<
104112
Instance extends Vue,
105113
Data,
@@ -109,7 +117,9 @@ export type CombinedVueInstance<
109117
SetupBindings = {},
110118
Mixin extends ComponentMixin = ComponentMixin,
111119
Extends extends ComponentMixin = ComponentMixin,
112-
PublicMixin = IntersectionMixin<Mixin> & IntersectionMixin<Extends>
120+
PublicMixin = IntersectionMixin<PrepareMixinData<Mixin>> &
121+
IntersectionMixin<Extends> &
122+
IntersectionMixin<ComponentOptions<any, any, any, any, any>> // prevent produce `never` in UnwrapMixinsType
113123
> = UnwrapMixinsType<PublicMixin, 'D'> &
114124
Data &
115125
UnwrapMixinsType<PublicMixin, 'M'> &

0 commit comments

Comments
 (0)