如何为打字稿功能定义通用类型?

时间:2020-10-09 19:23:30

标签: typescript generics

我想实现以下目标:

type FunctionType<T> = (a: T) => [T, string, T, T, string, T, number, number, T, string, number];

const A: <T extends {}>FunctionType<T> = (A) => [] as any

let b : FunctionType<string>

b = A("hello")

我希望能够静态生成泛型(例如第三行),因此以下方式不适合我的用例。

type FunctionType = <T>(a: T) => [T, string, T, T, string, T, number, number, T, string, number];

const A: FunctionType = (A) => [] as any

let b : FunctionType<string>  // not working!

b = A("hello")

0 个答案:

没有答案