Skip to content

typeof function guard doesn't work after update #28549

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
orlov-vo opened this issue Nov 15, 2018 · 2 comments
Closed

typeof function guard doesn't work after update #28549

orlov-vo opened this issue Nov 15, 2018 · 2 comments
Assignees
Labels
Bug A bug in TypeScript

Comments

@orlov-vo
Copy link

TypeScript Version: 3.1.6 (previous: 3.0.1)

Code

const data = typeof fetcherParams === 'function'
  ? fetcherParams()
  : fetcherParams

It doesn't work for me. Also, I tried to use instanceof and it works:

const data = fetcherParams instanceof Function
  ? fetcherParams()
  : fetcherParams

Expected behavior: no error with typeof statement

Actual behavior:

TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'Function | (() => object)' has no compatible call signatures.
@jack-williams
Copy link
Collaborator

I think this is working as intended after a (breaking) change in 3.1.

Read here.

@weswigham
Copy link
Member

Working as intended, technically, but the union of an untyped call and a typed call should still be callable. (Likely as the typed call but with an untyped return)

@weswigham weswigham added the Bug A bug in TypeScript label Nov 15, 2018
@weswigham weswigham self-assigned this Dec 8, 2018
@weswigham weswigham added this to the TypeScript 3.3 milestone Dec 8, 2018
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
Development

No branches or pull requests

3 participants