Skip to content

Unexpected lints when using "false &&" preceding a function call #37277

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
kyleshay opened this issue Mar 7, 2020 · 1 comment
Closed

Unexpected lints when using "false &&" preceding a function call #37277

kyleshay opened this issue Mar 7, 2020 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@kyleshay
Copy link

kyleshay commented Mar 7, 2020

TypeScript Version: 3.9.0-dev.20200306

Search Terms: false Unreachable code detected.

Code

const foo = (_: string) => console.log;
let bar: string | undefined;

// ✅
bar && foo(bar)

// ✅
if (false) {
    bar && foo(bar)
    ~~~~~~~~~~~~~~~ // "Unreachable code detected."
}

// ❌Actual
false && bar && foo(bar)
                    ~~~ // "Type 'undefined' is not assignable to type 'string'."

// ✅Expected
false && bar && foo(bar)
         ~~~~~~~~~~~~~~~ // "Unreachable code detected."

// ❓No lint error
false && foo('hello')

Expected behavior: false && bar && foo(bar) to note "Unreachable code detected."

Actual behavior: false && bar && foo(bar) notes "Type 'undefined' is not assignable to type 'string'."

Playground Link: https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=13&pc=1#code/MYewdgzgLgBAZiEMC8MAUB9AXDaAnASzAHMBKFAPhlEhABsBTAOjpGIG4BYAKEdgCMAhnhz4ixGAB8YAVzAATBnCIN5XbjyF4YAMh3xEaLaR48A9GZgBVMHgaDgAC0H9G1EIpiKoDYD-lMMDwEcOhwgnQQDOQA3jwwCTBauvoIIEbCJtwAvqbcFjAAgn4yETCAyAQwAEQAKgCeAA4MMADkcorKYKotMAQQMGAgsIIQEATEYC5uUEhQjc0tYiQtTFXmlgCiAB5NfqoV1TZ2Ds6uzaCe3r7+qzzhkc16ScIpBunGefdRrzQQ9MysYhoFqOBh1FqkIA

@nmain
Copy link

nmain commented Mar 9, 2020

The TS2345 you're getting is tracked by #26914 (note that the working case does give that error, just in a smaller error span)

I don't think I've seen an issue about diagnostics for false && /* ... */

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Mar 9, 2020
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

3 participants