-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
When compiling the following code: (the function call
takes a 0-argument function and returns its result)
type NoArgsFn<T> = () => T;
function call<T, Fn extends NoArgsFn<T>>(fn: Fn): T {
return fn();
}
let result: number = call(() => 1);
I get the following incorrect error: (on the last line)
try.ts(7,5): error TS2322: Type '{}' is not assignable to type 'number'.
The following workaround, adding an unused dummy argument of type T to the function, avoids this error:
type NoArgsFn<T> = () => T;
function call<T, Fn extends NoArgsFn<T>>(fn: Fn, dummy: T): T {
return fn();
}
let result: number = call(() => 1, -1);
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created