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
functionf(t: string){lets: "a"|"b"="a";constsneak=()=>{s="b";}if(t==="b"){sneak();}if(s==="b"){// <--- here should be no error!returntrue;}returnfalse;}
🙁 Actual behavior
In the line marked with a comment, an error is issued:
This comparison appears to be unintentional because the types '"a"' and '"b"' have no overlap.
🙂 Expected behavior
No error should occur here.
Additional information about the issue
In the example, the control flow analysis apparently does not recognise the effect of the inner function definition or its behaviour when computing the actual type of the variable s. This also happens in case of union types, for example. And it also happens for nested function declarations.
The text was updated successfully, but these errors were encountered:
jpilgrim
changed the title
Control flow analysis does not take effect of arrow function definition into account
Control flow analysis does not take effect of closure of inner function definition into account
Nov 21, 2024
jpilgrim
changed the title
Control flow analysis does not take effect of closure of inner function definition into account
Control flow analysis does not take effect of closure of inner functions into account
Nov 21, 2024
🔎 Search Terms
literal types, arrow function definition, control flow closure
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play/?ts=5.8.0-dev.20241121#code/GYVwdgxgLglg9mABMAFFAXIgzlATjMAcwEpEBvAKEWsQBsBTKbTAIgEMXEAfRFgI04BeXhwDcVGhAQ5sYemwDWiYSlKCAfOQk0aWZbwHidAX22IYwRGmWDh-FqUo6dWOYtVGapnRat7bdgKOZjq4jCC4SHgg9J7U3jRhUBFIwGy0WLEUxkA
💻 Code
🙁 Actual behavior
In the line marked with a comment, an error is issued:
This comparison appears to be unintentional because the types '"a"' and '"b"' have no overlap.
🙂 Expected behavior
No error should occur here.
Additional information about the issue
In the example, the control flow analysis apparently does not recognise the effect of the inner function definition or its behaviour when computing the actual type of the variable s. This also happens in case of union types, for example. And it also happens for nested function declarations.
The text was updated successfully, but these errors were encountered: