Use Case
我有一个类,它是通过传入方法列表来构造的,然后允许您通过该类调用这些方法(该类添加了一些附加功能).这些方法在调用时将类(Foo)绑定为其上下文.所以我有FooMethod
型.
class Foo {
public constructor(methods) {}
}
const myMethod: FooMethod<number> = function(value: number): number {
return value
}
const myMethods = [myMethod]
const foo = new Foo(myMethods)
type FooMethod<T> = (this: typeof foo, ...args: any[]) => T
type MyMethodParameters = Parameters<typeof myMethod> // any[]
Issue
将类型FooMethod<number>
添加到myMethod
常量.我无法再通过执行Parameters<typeof myMethod>
来获取函数的参数类型
Question
有没有办法让FooMethod
类型仍然推断参数?我希望能做到Parameters<typeof myMethod>
分,但仍能得到[number]
分