#this return type for static methods?

21 messages · Page 1 of 1 (latest)

uneven hornet
#

Hi guys i have question about the this return type for static methods like

class A{
  static Open(): this;
}
class B extends A{
  a: number;
}

B.Open().a; //should be valid but something is wrong
outer stag
#

@uneven hornet Doesn't really exist

#

There's a few workarounds in that thread though.

#

(I'm assuming you meant class B extends A in your example)

uneven hornet
#

ya

#

thx you anyway

#

Bruh its more like 6 years open and its not still improved / fixed

#

/resolve

#

!close

#

!open

#

@outer stag I am useing the JSDocs actually but is there way to redefine the types without creating the new method in that class? like virtual method

outer stag
#

TS doesn't prioritize changes based on how long the relative tickets have been open. (Really, nobody does)

outer stag
uneven hornet
#

not sure if i describe it correctly here is example:

class A{
  /* @returns {A}*/
  static Open(){return new this();}
}
class B extends A{
  /**
  * @static
  * @method Open
  * @returns B
  */
}

is that possible to change the type like this without implementing it?

#

@outer stag sorry this is last question

outer stag
#

Don't think so, no.

uneven hornet
#

Thank you for everything

outer stag
#

Some of the workarounds in the linked issue may still work with JSDoc syntax though

uneven hornet
#

thx