Skip to content
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

Switch on typeof does not narrow unknown correctly. #27180

Closed
jack-williams opened this issue Sep 18, 2018 · 0 comments · Fixed by #27680
Closed

Switch on typeof does not narrow unknown correctly. #27180

jack-williams opened this issue Sep 18, 2018 · 0 comments · Fixed by #27680
Labels
Bug A bug in TypeScript
Milestone

Comments

@jack-williams
Copy link
Collaborator

TypeScript Version: master 83fe1ea

Search Terms: switch typeof unknown

Code

// @strictNullChecks: true
function unknownNarrowing(x: unknown) {
    switch (typeof x) {
        case 'function': x; return; // x is unknown, should be Function
        case 'object': x; return; // x is unknown, should be object | null
    }
}

Expected behavior:

  • Narrowing unknown in switch at clause "function" should result in type Function.
  • Narrowing unknown in switch at clause "object" should result in type object | null.

Actual behavior:

  • Value of type unknown does not narrow.

Playground Link: N/A (Playground not on this version).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
2 participants