user1658162
user1658162

Reputation: 2811

Generic Type (typescript) error TS2314 on generic function type as input parameter

I'm getting stuck with a type error in typescript:

this is a sample code:

type myFunctionType<T, U> = (t: T, u: U) => U;
const testRoutine = <T, U>(myFn: (t: T, u: U) => U) => { };
const testRoutine2 = <T, U>(myFn: myFunctionType) => { };

I get the following error from typescript compiler on testRoutine2

error TS2314: Generic type 'myFunctionType' requires 2 type argument(s).

testRoutine look exactly as testRoutine2 so why that error from compiler? anybody can help? thanks

Upvotes: 0

Views: 59

Answers (1)

Derviş Kayımbaşıoğlu
Derviş Kayımbaşıoğlu

Reputation: 30545

try in this way

const testRoutine2 = <T, U>(myFn: myFunctionType<T,U>) => { };

Upvotes: 2

Related Questions