feat: allow mixins to accept generics
This commit is contained in:
parent
be95ad00e9
commit
62214fa42e
@ -4,6 +4,10 @@ interface ComponentConstructor<This = Component> {
|
|||||||
new (): This
|
new (): This
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ComponentConstructorWithMixins<This> {
|
||||||
|
new <P = {}, D = {}>(): This & { $data: D } & D & { $props: Readonly<P> } & P
|
||||||
|
}
|
||||||
|
|
||||||
// mind = blown
|
// mind = blown
|
||||||
// https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection-type
|
// https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection-type
|
||||||
type UnionToIntersection<U> = (U extends any
|
type UnionToIntersection<U> = (U extends any
|
||||||
@ -17,9 +21,9 @@ type ExtractInstance<T> = T extends (infer U)[]
|
|||||||
: never
|
: never
|
||||||
|
|
||||||
export function mixins<
|
export function mixins<
|
||||||
T extends ComponentConstructor[],
|
T extends ComponentConstructor[] = [],
|
||||||
V = ExtractInstance<T>
|
V = ExtractInstance<T>
|
||||||
>(...args: T): ComponentConstructor<V>
|
>(...args: T): ComponentConstructorWithMixins<V>
|
||||||
export function mixins(...args: any[]): any {
|
export function mixins(...args: any[]): any {
|
||||||
// TODO
|
// 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() {
|
created() {
|
||||||
this.foo
|
this.foo
|
||||||
this.bar
|
this.bar
|
||||||
|
this.baz
|
||||||
this.test()
|
this.test()
|
||||||
this.ok()
|
this.ok()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user