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
This is intentional since the value of obj.name "could" change types between when the narrowing occurred and when the callback was invoke. See also #11498
The second is that function calls do not reset narrowings. In other words:
functionfn(obj: {name: string|number}){if(typeofobj.name==="string"){console.log("Here");// Does not errorconsole.log(obj.name.toLowerCase());}}
This is intentional behavior, even though console.log could have mutated obj. This rule is consistently applied, even with the function is in-principle inspectable to actually have side effects
functionfn(obj: {name: string|number}){if(typeofobj.name==="string"){mut();// Does not errorconsole.log(obj.name.toLowerCase());}functionmut(){obj.name=42;}}
The text was updated successfully, but these errors were encountered:
TypeScript has two narrowing-related behaviors that are both intentional. Please do not log additional bugs on this; see #9998 for more discussion.
The first is that narrowings are not respected in callbacks. In other words:
This is intentional since the value of
obj.name
"could" change types between when the narrowing occurred and when the callback was invoke. See also #11498The second is that function calls do not reset narrowings. In other words:
This is intentional behavior, even though
console.log
could have mutated obj. This rule is consistently applied, even with the function is in-principle inspectable to actually have side effectsThe text was updated successfully, but these errors were encountered: