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
declarefunctiontryParse(cb: (abort: ()=>never)=>unknown): void;typeA={type: "A"};typeB={type: "B"};declareconstnode: A|B;tryParse(abort=>{abort;// ^?if(node.type==="A")abort();returnnodesatisfiesB;// "Type 'A | B' does not satisfy the expected type 'B'"})tryParse((abort: ()=>never)=>{if(node.type==="A")abort();returnnodesatisfiesB;})
π Actual behavior
In the first case, node is not refined to B but it still has type A | B
π Expected behavior
The two usages of tryParse are exactly the same, abort has exactly the same type in both, so they should both narrow the type of node.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered:
While not precisely a duplicate of #51075, this is related to that and a known limitation of never narrowing. In order for narrowing to work, the type of the variable being called needs to be known before the inference pass happens.
π Search Terms
function callback never type narrowing inference
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXwxgE8AFWAZxAAowAjALniqlpxg0aoEp4BeAPnioQANxAweA+GgDWqHAHdUXRiJxZgAbgBQ2jEQAOCAIJ94AbwKGQjAETHb8AL479R+ACEzltzfi2PRxddUEhYBDA8cgwhHFBGUwAfTx09YjIYSmZWdj5Bc214IvgWNgwdYvgAeir4AD0Afl1KrEQmeVAAOl8+Xl5-Bx5S9m5UyrgMZBh8DoRyKGxyRCwQchTq2tsAFWt4AHIkzz34YBxV2Jj5xcQiAgALBBAADyNMEGArdz2PPdttJy4ukIpAo1GyZU4kkEwjEEjyFkKxVa7TiIG6uz6-XstiGOQwo2axQmUxmqPgVywSxWaw8OgB2iAA
π» Code
π Actual behavior
In the first case,
node
is not refined toB
but it still has typeA | B
π Expected behavior
The two usages of
tryParse
are exactly the same,abort
has exactly the same type in both, so they should both narrow the type ofnode
.Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: