I need to add properties to Object.constructor
on a specific class.
I am Using lib.es5.d.ts
I have tried overriding the global Object like:
type EntityConstructor = Function & {behaviors: string[]}
declare global {
interface Object {
constructor: EntityConstructor
}
}
This throws an error:
Subsequent property declarations must have the same type.
Property 'constructor' must be of type 'Function', but here has type 'EntityConstructor'.
I don't need this to be an override it could be for a explicit class.
USAGE EXAMPLE: To clarify why and how I want this property...
I am using typescript mixins
I have a method that takes a set of ConstrainedMixin
constructors, applies them to a base class to create a new Constructor for the mixed class. Then I want to store the list of applied mixin names on that new constructor as a new property. This looks like:
import compose from 'lodash.flowright';
export type ConstrainedMixin<T = {}> = new (...args: any[]) => T;
class Entity {
static behaves(...behaviors: Array<ConstrainedMixin>){
const newEnt = compose.apply(
null,
behaviors,
)(Entity);
newEnt.behaviors = behaviors.map((behaviorClass) => behaviorClass.name);
return newEnt;
}
}