Skip to content

typeof function guard doesn't work after update #28549

Closed
@orlov-vo

Description

@orlov-vo

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.

Activity

jack-williams

jack-williams commented on Nov 15, 2018

@jack-williams
Collaborator

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

Read here.

weswigham

weswigham commented on Nov 15, 2018

@weswigham
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)

self-assigned this
on Dec 8, 2018
added this to the TypeScript 3.3 milestone on Dec 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @orlov-vo@weswigham@jack-williams

      Issue actions

        typeof function guard doesn't work after update · Issue #28549 · microsoft/TypeScript