typescript - Access prototype from generic -


is possible class generic such class foo<a> {} access a's prototype or use typeguard on a, or run sort of logic based on a's type alone - without having been provided class, interface, or instance foo's constructor (i.e. foo has no constructor or constructor not accept argument of type a)?

there several answers accessing constructor, such generic type inference class argument interested in running different logic based on type, not instantiating new instance of it.

specifically, want know if a.prototype has method defined on it.

if goal allow a classes specific function can use extends mechanism generic well, this:

interface b {    mymandatoryfunction() }  class foo<a extends b> {    //... } 

if action in generic class based on on a having function or not on prototype, have instantiate a object , @ it's prototype because typescript typing involved @ compilation , checking type of object during code execution done in js instanceof method , not applicable types


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -