Last active
January 30, 2020 13:14
-
-
Save antongolub/800f163422d69a9c8492140a9248745d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type IMixinsApplier = <T extends IConstructable, U extends IConstructable[]>(target: T, ...mixins: U) => IMixedAsClass<T, U> | |
type IMixedAsClass<T extends IConstructable, U extends any[]> = T | |
& UnionToIntersectionOfConstructables<U[number]> | |
& IConstructable<InstanceType<T> & UnionToIntersectionOfInstances<U[number]>> | |
interface IConstructable<T = {}> extends Function { | |
new (...args: any[]): T | |
} | |
export type IExtendsCondition<T, E, R1, R2> = T extends E | |
? R1 | |
: R2 | |
export type InstanceTypeOrType<T> = IExtendsCondition<T, IConstructable, InstanceType<IConstructable & T>, T> | |
export type ConstuctableOrEmpty<T> = IExtendsCondition<T, IConstructable, T, {}> | |
export type UnionToIntersectionOfConstructables<U> = (U extends any | |
? (k: ConstuctableOrEmpty<U>) => void | |
: never) extends (k: infer I) => void | |
? I | |
: never | |
export type UnionToIntersectionOfInstances<U> = (U extends any | |
? (k: InstanceTypeOrType<U>) => void | |
: never) extends (k: infer I) => void | |
? I | |
: never |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment