-
-
Notifications
You must be signed in to change notification settings - Fork 7k
/
mixins.ts
21 lines (18 loc) · 928 Bytes
/
mixins.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* eslint-disable max-len, import/export, no-use-before-define */
import Vue, { VueConstructor } from 'vue'
export default function mixins<T extends VueConstructor[]> (...args: T): ExtractVue<T> extends infer V ? V extends Vue ? VueConstructor<V> : never : never
export default function mixins<T extends Vue> (...args: VueConstructor[]): VueConstructor<T>
export default function mixins (...args: VueConstructor[]): VueConstructor {
return Vue.extend({ mixins: args })
}
/**
* Returns the instance type from a VueConstructor
* Useful for adding types when using mixins().extend()
*/
export type ExtractVue<T extends VueConstructor | VueConstructor[]> = T extends (infer U)[]
? UnionToIntersection<
U extends VueConstructor<infer V> ? V : never
>
: T extends VueConstructor<infer V> ? V : never
type UnionToIntersection<U> =
(U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never