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
Yeah so the problem here is that narrowing is done for each expression individually and el instanceof A || el2 instanceof A doesn't give the compiler enough information to narrow either one (one of them is an A, but which one?). When it gets the && check it can narrow that (it now knows both are As), but it can't do anything in the else clause because at that point the compiler would have to look backwards at both past type checks to actually narrow something.
TS doensn't internally track type guards as such--a guard either narrows a type or it doesn't, and then the compiler moves on. Further narrowings are based only on the types they are given as input.
Bug Report
🔎 Search Terms
type narrowing
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
if el or el2 are instance of A
AND
! (el and el2) instance of A
AND
el isntance of A
then el2 can only be string - but is shown as string|A
🙂 Expected behavior
(😅 i know its over the top )
but if possible i would like el2 to be narrowed down to string
The text was updated successfully, but these errors were encountered: