J'obtiens l'erreur suivante :
<br i="6"/>
TS2351 Cannot use 'new' with an expression whose type lacks a call or construct signature.<br i="7"/>
<br i="10"/>
class A {<br i="11"/>
constructor() { ... }<br i="12"/>
refresh() { return new this.constructor; }<br i="13"/>
}<br i="14"/>
nouveau this.constructor fonctionne en JS pur.
Merci:)
Le type de constructor
est juste Function
, malheureusement. Vous pouvez écrire ceci à la place :
class A { constructor() { } refresh() { return new (<typeof A>this.constructor); } }
Commentaire le plus utile
Le type de
constructor
est justeFunction
, malheureusement. Vous pouvez écrire ceci à la place :