【发布时间】:2021-04-13 23:42:00
【问题描述】:
标题可能令人困惑,我不知道如何正确表达它,但总之我想完成以下工作:
type A<T extends new (...args: any) => any = any> = [T, Required<InstanceType<T>>];
function b<T extends new (...args: any) => any, T2 extends new (...args: any) => any>(...args: [A<T>, A<T2>?]) { };
class C { d?: string; e?: number };
class F { g?: string; h?: number };
b([C, { d: '', e: 2 }], [F, { g: '', h: 3 }]);
但不必在b 函数中具有T, T2 类型参数,因为在我的用例中,该函数没有定义的参数长度。这可能吗?如果没有,有更好的解决方案吗?
【问题讨论】:
-
也许 TS4.0 中的新可变元组类型会有所帮助:typescriptlang.org/docs/handbook/release-notes/… 还有这个包含一些我认为你想要的内容:stackoverflow.com/questions/48872328/…
-
您能详细说明一下吗?我查看了链接,但无法弄清楚这里到底适用于我的情况。
-
我可能误解了您要查找的内容。
标签: typescript