标签:infer type ext typeof rgb rgba func any key
type GetIndexType_0<T> = T extends [infer T0, ...infer TS] ? T0 : never; type GetIndexType_1<T> = T extends [infer T0, infer T1, ...infer TS] ? T1 : never; interface GetIndexType<T> { 0: GetIndexType_0<T> 1: GetIndexType_1<T> } type GetPar<T extends (...args: any) => any, TI extends keyof GetIndexType<any>> = T extends (...args: infer TS) => any ? GetIndexType<[...TS]>[TI] : never; function f(n: number, s: string, re: RegExp) { } let n: GetPar<typeof f, 0>; let s: GetPar<typeof f, 1>;
貌似typescript暂时不能跟C++一样能够进行模板循环,所以只能跟C#一样把模板手动写出来,我只写了取前两个参数的
标签:infer type ext typeof rgb rgba func any key
原文地址:https://www.cnblogs.com/leikaifeng/p/14615603.html