TypeScript Version: 3.9.2
Search Terms:
instanceof narrow derived
Code
classCustomErrorextendsError{extra: string='hello'}consterror: Error=newCustomError()if('extra'inerror){// code path reached at runtimeerror// type: never}else{// code path not reached at runtimeerror// type: Error}Expected behavior:
error inside the if block is still of type Error
Actual behavior:
error inside the if block is of type never
Playground Link:https://www.typescriptlang.org/play?#code/MYGwhgzhAEDCCuEAuB7AtgUQE5ZV6ApgB5IEB2AJjNrvgN6ElZgBc0yWAlmQObQC80AOQALAiBAoh0AL4AoYCjLJCOPGxp4B0MgQDucRKkxqsACgCUczgDNoZocSTNp3VbQvQ6c6L-daAegDoJABPAAcCNl0ANwIsORlCEAgCLx8-eNpoIJCIqOhNBJkgA
Related Issues:
None that seemed to match.
TypeScript Version: 3.9.2
Search Terms:
instanceof narrow derived
Code
Expected behavior:
errorinside theifblock is still of typeErrorActual behavior:
errorinside theifblock is of typeneverPlayground Link:https://www.typescriptlang.org/play?#code/MYGwhgzhAEDCCuEAuB7AtgUQE5ZV6ApgB5IEB2AJjNrvgN6ElZgBc0yWAlmQObQC80AOQALAiBAoh0AL4AoYCjLJCOPGxp4B0MgQDucRKkxqsACgCUczgDNoZocSTNp3VbQvQ6c6L-daAegDoJABPAAcCNl0ANwIsORlCEAgCLx8-eNpoIJCIqOhNBJkgA
Related Issues:
None that seemed to match.