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
At present there doesn't appear to be a way to define an enum in a union type and have it narrowed correctly. Here's an example:
functionf1(x: number|string){if(typeofx==="number"){returnx+10;}else{returnx.length;}}enumColour{red,blue}functionf2(x: Colour|string){if(typeofx==="number"){returnx+10;// Error because x is Colour | string}else{returnx.length;}}varx=f1(1);vary=f2(Colour.blue);
The type guard typeof x === 'number' should probably narrow the type correctly and not report an error in f2.