/** * Type helpers for Mixin */ type Constructor = new (...args: U) => T; type ConstructorParams = T extends new (...args: infer U) => any ? U : never; type InstanceType = T extends new (...args: any[]) => infer U ? U : never; type MergeInstances = { [P in keyof T]: P extends keyof U ? U[P] : T[P]; } & U; /** * #### Mixin * * Creates a class that combines two classes using the mixin pattern. * The resulting class extends the first class and includes all properties and methods from the second class. * * * * * * Example: * ```typescript * import { mixin } from "@thalesrc/js-utils/class"; * * class Timestamped { * timestamp = Date.now(); * getAge() { * return Date.now() - this.timestamp; * } * } * * class User { * constructor(public name: string) {} * greet() { * return `Hello, ${this.name}`; * } * } * * class TimestampedUser extends mixin(User, Timestamped) {} * * const user = new TimestampedUser(['John'], []); * console.log(user.greet()); // "Hello, John" * console.log(user.getAge()); // Time since creation * ``` * * @param Base The base class to extend * @param Mixin The mixin class to combine * @returns A new class that combines both classes */ export declare function mixin, U extends Constructor>(Base: T, Mixin: U): Constructor, InstanceType>, [ ConstructorParams, ConstructorParams ]>; export {};