Skip to content

Type guards in switch statement #19861

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
srolel opened this issue Nov 9, 2017 · 2 comments
Closed

Type guards in switch statement #19861

srolel opened this issue Nov 9, 2017 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@srolel
Copy link
Contributor

srolel commented Nov 9, 2017

TypeScript Version: 2.7.0-dev.201xxxxx

Code

function foo(baz: boolean | (() => boolean)) {
    switch (typeof baz) {
        case 'boolean':
            break;
        case 'function':
            baz();
            break;
    }
}

Expected behavior:

Should compile, similar to the equivalent usage of if statement type guards.

Actual behavior:

Does not compile with error:

[ts] Cannot invoke an expression whose type lacks a call signature. Type 'Boolean' has no compatible call signatures.

@mhegazy
Copy link
Contributor

mhegazy commented Nov 9, 2017

Duplicate of #2214

@mhegazy mhegazy marked this as a duplicate of #2214 Nov 9, 2017
@mhegazy mhegazy added the Duplicate An existing issue was already created label Nov 9, 2017
@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants