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
// A *self-contained* demonstration of the problem follows...// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc.interfaceTestHash{[index: string]: boolean;}typeTestType=boolean|TestHash;functiontestTypeOf(value: TestType){constvalueType=typeofvalue;if(valueType==="boolean"){returnvalue;}if(valueType==="object"){returnObject.keys(value).every((key)=>value[key]);}return!!value}
Expected behavior:
The cached result of typeof should also be used to narrow down the union type.
Actual behavior:
It errors with:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'TestType'. No index signature with a parameter of type 'string' was found on type 'TestType'.
TypeScript Version:
v4.0.5
Search Terms: typeof, cached typeof
Code
Expected behavior:
The cached result of
typeof
should also be used to narrow down the union type.Actual behavior:
It errors with:
Playground Link:
Broken: https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgCoQM5gBJwwC2QG8AoZc5AbVABMIAPALmSylAHMBdZgIwHs+AGwhwQAbhIBfEmACeABxTosqBSgC8yfkJEhkAHzSYcefBJIwAriARhgfPZBVqA8jAAUANziDLEZspgqooAlMRkFAgOWMjevhDBGshyinwwsT5+5hTIwOlemQlqyOqlyABE2sKi5WGkOTlQEGCWUHpxWRHk0l25+R1FiiVl5Xw8AFYQtrXhDRRNLW3ILhNTYAB0ANYQshgF8SHrEJ7Qsu7u27Jh6gB8GfGUl5whEjk9jc2tegCE3wNSJEB5CAA
Working: https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgCoQM5gBJwwC2QG8AoZc5AbVABMIAPALmSylAHMBdZgIwHs+AGwhwQAbhIBfEmACeABxTosqBSgC8yfkJEhkAHzSYcefBJIwAriARhgfPZBVqA8jAAUANziDLEZspgqooAlMRkFMAwyO5yinzR3r4a6poARNrComlhpBT5yFAQYJZQekl+EvnSEeRRMXEQCcgVKel8PABWELY54QUURSVlyC5dPWAAdADWELIYXj5+IZMQntCy7u6zsmHqAHwtSxCUO5whVRQ1+UOlegCE961SJK-kQA
Related Issues:
The text was updated successfully, but these errors were encountered: