Type 'T & Function' has no call signatures [duplicate]

1 day ago 2
ARTICLE AD BOX

I would like to have a function that either call obj with item as param if obj is a function else juste return the object.

I've done it like this:

export function getValue<T>( obj: T | ((item: any) => T), item: any ): T { return typeof obj === "function" ? obj(item) : obj; }

But I get the issue:

This expression is not callable. Not all constituents of type '((item: any) => T) | (T & Function)' are callable. Type 'T & Function' has no call signatures.ts(2349)

Because there are some cases like:

class Foo {}; typeof Foo; // 'function'

How could I make this work without using as ?

Ratinax's user avatar

1

Read Entire Article