How to get the child type from a function defined on the parent type?


#1

I have a parametric Parent and several children types:

extendable entity type Parent<P>
entity type ChildA extends Parent<A>
entity type ChildB extends Parent<B>

On the type Parent, I defined a function foo that is common to all the children but in which I want to create an instance of the child, e.g.:

function foo() {
    <Child>.upsert({...});
}

// when I call
ChildA.foo()
// I expect to have a new instance of ChildA in my database

How do I access to the “current” child type on from the implementation of a function on the type Parent?


#2

I think:

function foo() {
  this.type().upsert()
}

should work if the function is a member method.

this.upsert()

if a static method