You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Extending global Function interface breaks instanceof Type Guard #26159
Search Terms:
global Function interface
instanceof
Type Guard
Code
declare global {interfaceFunction{now(): string;}}Function.prototype.now=function(){return"now"}classX{staticnow(){return{}}why(){}}classY{}console.log(X.now())// works as expectedconsole.log(Y.now())// works as expectedexportconstx: X|number=Math.random()>0.5 ? newX() : 1if(xinstanceofX){x.why()// should compile}
Expected behavior:
Code compiles
Actual behavior:
Compilation failed
"Property 'why' does not exist on type 'number'."
Andy (Andrewkraft) (@Andy-MS) You're right, I forgot to emphasize on this. It happens for classes that their static fields override some new added properties to the Function interface.
But this works as expected though:
console.log(X.now())// works as expectedconsole.log(Y.now())// works as expected
Activity
kobiburnley commentedon Aug 2, 2018
Andy (Andrewkraft) (@Andy-MS) You're right, I forgot to emphasize on this. It happens for classes that their static fields override some new added properties to the Function interface.
But this works as expected though: