【发布时间】:2021-05-12 10:27:03
【问题描述】:
使用此代码 (playground):
declare class Test<P = unknown, R = unknown> {
test(p: P): R;
}
declare class M extends Test {
test(q: number): boolean;
}
// these lines are not in real code. This is an example of what TS
// could infer from my code and what I would like to find using Compiler API
type Sgn<M> = M extends Test<infer P, infer R> ? [P, R] : never;
type sgn = Sgn<M>; // [number, boolean]
typescript 可以从类声明中的方法 test 推断出类 M(P = number,R = boolean)的隐式类型参数。
我想用Compiler API 做同样的事情。我有program.typeChecker,我被困在这里。如何获得隐式类型参数?
【问题讨论】:
标签: typescript typescript-compiler-api