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
typeTChildrenFunc=()=>string;typeTChildren=TChildrenFunc|string;functionisFunction(render: TChildren): render is TChildrenFunc{returntypeofrender==="function";}// render is of type TChildrenconstcacheResult=isFunction(render);// errors belowconsttest=cacheResult ? render() : render;
The text was updated successfully, but these errors were encountered:
rssfrncs
changed the title
Unable to cache result of user defined type guard function
Unable to store and reuse result of user defined type guard function
Jun 15, 2018
functiontwostep(x: symbol|string){constisSymbol=typeofx==="symbol";if(!isSymbol){console.log(`Type of x is still string | symbol here: ${x}`);}}functiononestep(x: symbol|string){if(typeofx!=="symbol"){console.log(`Type of x is now just string: ${x}`);}}
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
TypeScript Version: 2.9.1
Search Terms: caching type guard result
Code
Expected behavior:
Same as in-lining the type guard call.
Actual behavior:
TypeScript is unable to infer the correct type.
Playground Link: https://codesandbox.io/s/30v146k811 Check
Hello.tsx
Related Issues: Nope.
The text was updated successfully, but these errors were encountered: