InversifyJS icon indicating copy to clipboard operation
InversifyJS copied to clipboard

Add a getConstructor internal function

Open notaphplover opened this issue 4 years ago • 0 comments

We currently use the constructor property to access the constructor of an instance. Our use cases allow this operation to be performed, but I think it has some cons we often access the constructor property from any typed values. There is also a more standard way to access the constructor of an object:

    function getConstructor<T>(value: T): typeof T {
        return Object.getPrototypeOf(value).constructor;
    }

which would (kind of) work with number values which has no constructor (even if Number constructor generates Number objects instead of number primitives I think we could deal with it)

A utility function would allow us to have an uniform and typed way to get the constructor of an instance

notaphplover avatar May 09 '21 11:05 notaphplover