泛型函数类型作为输入参数的泛型类型(打字稿)错误 TS2314
Generic Type (typescript) error TS2314 on generic function type as input parameter
我遇到了打字稿中的类型错误:
这是示例代码:
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) => { };
我在 testRoutine2 上从打字稿编译器收到以下错误
error TS2314: Generic type 'myFunctionType' requires 2 type argument(s).
testRoutine 看起来与 testRoutine2 完全一样,那么为什么编译器会出现错误?
有人可以帮忙吗?
谢谢
这样试试
const testRoutine2 = <T, U>(myFn: myFunctionType<T,U>) => { };
我遇到了打字稿中的类型错误:
这是示例代码:
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) => { };
我在 testRoutine2 上从打字稿编译器收到以下错误
error TS2314: Generic type 'myFunctionType' requires 2 type argument(s).
testRoutine 看起来与 testRoutine2 完全一样,那么为什么编译器会出现错误? 有人可以帮忙吗? 谢谢
这样试试
const testRoutine2 = <T, U>(myFn: myFunctionType<T,U>) => { };