export interface Constructor { new(...args: any[]): T; } /** * Given a Functional constructor (a function that returns an object, but is not meant to be used with `new`), return a Class that can be extended * * Example: * ```js * const BaseMoment = makeExtensible(moment); * class SubMoment extends BaseMoment { } * ``` */ export function makeExtensible(constructCall: (...args) => T, prototype?: any): Constructor { const extensible = function (...args) { // Object.assign(this, constructCall(...args)); Object.setPrototypeOf(this, constructCall(...args) as any) } extensible.prototype = prototype || (constructCall as any).fn || constructCall.prototype; return extensible as any; }