可以推导出一个元组里所有函数的返回值类型吗?求解
// 例如一个数组 [() => 1, () => 's'] // 期望推导出 [number, string]
const s = [() => 1, () => 's'] as const; type S = typeof s; type M<T extends ReadonlyArray<() => any>> = { -readonly [key in keyof T]: T[key] extends () => any ? ReturnType<T[key]> : never; } type R = M<S>;
这样试试
1.4m articles
1.4m replys
5 comments
57.0k users