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

(typeof x == foo) fails to typecheck as (typeof x == 'foo') #21315

Closed
thomaseding opened this issue Jan 20, 2018 · 2 comments
Closed

(typeof x == foo) fails to typecheck as (typeof x == 'foo') #21315

thomaseding opened this issue Jan 20, 2018 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@thomaseding
Copy link

thomaseding commented Jan 20, 2018

TypeScript Version: 2.6

Search Terms:
typeof

Code

function test(x: Function | string) { 
    if (typeof x === `function`) { 
        x(); // Typechecker fails to infer callable.
    }
}

Expected behavior:
Program typechecks. (Because changing `function` to 'function' works.)

Actual behavior:
Program does not typecheck.

Playground Link:
https://www.typescriptlang.org/play/#src=function%20test(x%3A%20Function%20%7C%20string)%20%7B%20%0D%0A%20%20%20%20if%20(typeof%20x%20%3D%3D%3D%20%60function%60)%20%7B%20%0D%0A%20%20%20%20%20%20%20%20x()%3B%0D%0A%20%20%20%20%7D%0D%0A%7D

Related Issues:

@ajafff
Copy link
Contributor

ajafff commented Jan 20, 2018

Can you try typescript@rc or @next? This should already be fixed.

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Jan 20, 2018
@mhegazy mhegazy closed this as completed Jan 20, 2018
@mhegazy mhegazy added this to the TypeScript 2.7 milestone Jan 20, 2018
@RyanCavanaugh RyanCavanaugh added Duplicate An existing issue was already created and removed Fixed A PR has been merged for this issue labels Jan 22, 2018
@RyanCavanaugh
Copy link
Member

If you had searched "typeof template", you would have found #20949

@microsoft microsoft locked and limited conversation to collaborators Jul 3, 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

4 participants