【发布时间】:2019-12-17 21:54:07
【问题描述】:
是否有可能描述由函数参数推断的类型?我需要这样的东西:
// some fn I have no control over its params
function someFn(a: string, b?: number, c?: any): any { /* ... */ }
// my wanted type that describes the args as object-records:
const result: MyType<typeof someFn> = {
a: 'str',
b: 42,
c: null
};
我无法控制函数参数的签名,因此无法将其转换为 someFn(args: SomeFnArgs) 和 MyType<SomeFnArgs>。
我什至不知道是否可以描述类型。
【问题讨论】:
标签: typescript typescript-typings typescript-generics