]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat: allow mixins to accept generics
authorEvan You <yyx990803@gmail.com>
Tue, 16 Oct 2018 14:50:23 +0000 (10:50 -0400)
committerEvan You <yyx990803@gmail.com>
Tue, 16 Oct 2018 14:50:23 +0000 (10:50 -0400)
packages/core/src/optional/mixin.ts

index 0fbd7fca6b9329c3bff7523fcb40b260683fe868..7b56416a56c6dc887a2ab7960d134c0f77e7b907 100644 (file)
@@ -4,6 +4,10 @@ interface ComponentConstructor<This = Component> {
   new (): This
 }
 
+interface ComponentConstructorWithMixins<This> {
+  new <P = {}, D = {}>(): This & { $data: D } & D & { $props: Readonly<P> } & P
+}
+
 // mind = blown
 // https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection-type
 type UnionToIntersection<U> = (U extends any
@@ -17,9 +21,9 @@ type ExtractInstance<T> = T extends (infer U)[]
   : never
 
 export function mixins<
-  T extends ComponentConstructor[],
+  T extends ComponentConstructor[] = [],
   V = ExtractInstance<T>
->(...args: T): ComponentConstructor<V>
+>(...args: T): ComponentConstructorWithMixins<V>
 export function mixins(...args: any[]): any {
   // TODO
 }
@@ -38,10 +42,11 @@ class Bar extends Component<{ bar: string }> {
   }
 }
 
-class Baz extends mixins(Foo, Bar) {
+class Baz extends mixins(Foo, Bar)<{ baz: number }> {
   created() {
     this.foo
     this.bar
+    this.baz
     this.test()
     this.ok()
   }