-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Open
Labels
BugA bug in TypeScriptA bug in TypeScript
Milestone
Description
TypeScript Version: 3.9.0 (Nightly)
Search Terms: T | (() => T)
, T & Function
Code
type Initializer<T> = T | (() => T)
// type Initializer<T> = T extends any ? (T | (() => T)) : never
function correct<T>(arg: Initializer<T>) {
return typeof arg === 'function' ? arg() : arg // error
}
Line 2 provides a workaround for this.
More info on stackoverflow.
Expected behavior: no errors
Actual behavior: This expression is not callable. Not all constituents of type '(() => T) | (T & Function)' are callable. Type 'T & Function' has no call signatures.
Playground Link: here.
Related Issues: none
bela53, vkatushenok, balazsotakomaiya, PezCoder, denis-sokolov and 63 morecaptain-yossarian, 100terres, timfuhrmann, productdevbook, pckilgore and 1 more
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScript