We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
This is not a regression, it never worked.
https://www.typescriptlang.org/play?ts=5.2.2#code/JYOwLgpgTgZghgYwgAgEJwM4oN4ChnJgCeADhAFzIDkMA9rVcgD7UBGcUVuAvrrqJFiIUAMXrIIAD0ggAJhjSYc+QqQrU6DANwrNlDGCigA5jt79w0eEkVQJ0iHIXosyPAWJlKVdpx0FfShAAVwBbVmgzPhhgkAQwYFoQZGMIMAA1AAoASkoxWmZbNxUCKDTgqGSQgBtqgEIo3AQkg2QAN2QAXhS0rOydfhhMzLaAOk8IbK7O7p8OKin3dvG1Hj5cAHoN5AB1WigAawxcDAB3YDAEAAtkEZWyReQt5AAeGc6VBCU2efIS5d8-gIyFYZTgBwGBC+rho9Cof2By00QICYIha022wAIrQIAoQLQwMhTvsDidzpcbsMxhNso9nm8Zp9vnNOAjgWNAf9QRBwZDkNCULCGOyCGNkdy0WYgA
interface Base { type: 'foo' | 'bar' } interface Foo extends Base { type: 'foo'; foo: string; } interface Bar extends Base { type: 'bar'; bar: number; } function getV(): Foo | Bar { return null!; } const v = getV(); if((v.type) === 'bar') { v.type } // Works switch (v.type) { // <=== case 'bar': v.bar; break; case 'foo': v.foo; break; } // Does not work switch ((v.type)) { // <=== case 'bar': v.bar; // KO break; case 'foo': v.foo; // KO break; }
With extra braces in the switch, narrowing is broken.
switch
switch ((v.type)) { // <=== extra braces case 'bar': console.log(v.bar); break; case 'foo': console.log(v.foo); break; }
switch ((v.type)) should behave as switch (v.type).
switch ((v.type))
switch (v.type)
There is no such issue on a if condition.
if
The text was updated successfully, but these errors were encountered:
typeof
Successfully merging a pull request may close this issue.
Uh oh!
There was an error while loading. Please reload this page.
π Search Terms
π Version & Regression Information
This is not a regression, it never worked.
β― Playground Link
https://www.typescriptlang.org/play?ts=5.2.2#code/JYOwLgpgTgZghgYwgAgEJwM4oN4ChnJgCeADhAFzIDkMA9rVcgD7UBGcUVuAvrrqJFiIUAMXrIIAD0ggAJhjSYc+QqQrU6DANwrNlDGCigA5jt79w0eEkVQJ0iHIXosyPAWJlKVdpx0FfShAAVwBbVmgzPhhgkAQwYFoQZGMIMAA1AAoASkoxWmZbNxUCKDTgqGSQgBtqgEIo3AQkg2QAN2QAXhS0rOydfhhMzLaAOk8IbK7O7p8OKin3dvG1Hj5cAHoN5AB1WigAawxcDAB3YDAEAAtkEZWyReQt5AAeGc6VBCU2efIS5d8-gIyFYZTgBwGBC+rho9Cof2By00QICYIha022wAIrQIAoQLQwMhTvsDidzpcbsMxhNso9nm8Zp9vnNOAjgWNAf9QRBwZDkNCULCGOyCGNkdy0WYgA
π» Code
π Actual behavior
With extra braces in the
switch
, narrowing is broken.π Expected behavior
switch ((v.type))
should behave asswitch (v.type)
.There is no such issue on a
if
condition.The text was updated successfully, but these errors were encountered: