'How to resolve the question of typescript generic function
class Context {}
declare function call<C>( method: ( value: unknown, context: C ) => unknown ): any;
declare function fn1<T>( value: T, context: Context ): Promise<T>;
declare function fn2( value: unknown, context: Context ): unknown;
call( fn1 );
call( fn2 );
I have code above, and you can also view it in Playground.
call( fn1 ) triggered error message:
Argument of type '<T>(value: T, context: Context) => Promise<T>' is not assignable to parameter of type '(value: unknown, context: unknown) => unknown'.
Types of parameters 'context' and 'context' are incompatible.
Type 'unknown' is not assignable to type 'Context'.(2345)
But call( fn2 ) works well.
Is it because fn1 is a generic function and why?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
