Skip to content

Discriminant narrow not work when not union type. #39110

New issue

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

Closed
ShuiRuTian opened this issue Jun 17, 2020 · 1 comment
Closed

Discriminant narrow not work when not union type. #39110

ShuiRuTian opened this issue Jun 17, 2020 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@ShuiRuTian
Copy link
Contributor

TypeScript Version: 3.7.x-dev.201xxxxx

Search Terms:

Code

// A *self-contained* demonstration of the problem follows...
// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc.
interface X {
    type: 'A'
}

function ffff3(x: X) {
    if (x.type === 'A') {
        return;
    }
    x  // should be never, but still X.
}

Expected behavior:
the type of variable x in the last line of the function should be narrowed to never.

Actual behavior:
It is not narrowed.

Playground Link:
https://www.typescriptlang.org/play/index.html#code/JYOwLgpgTgZghgYwgAgBrIN4Chm+WATwAcIAuZAcgEEKsBfLUSWRFATUxz0JPIrdoMsMAK4gEYYAHsQyGPJgBmABQAPcqgA+bAJSc8yYDGRqAdDxQBea5Rp7sBg1AhgRUEAG4uuBgaMnVc2IrG34Ke29HZ1d3LwNfPFV6IA

Related Issues:

@RyanCavanaugh
Copy link
Member

Duplicate e.g. #38963

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants