如何使用Typescript编译器API解析类型引用?

时间:2020-03-29 09:10:20

标签: javascript typescript typescript-compiler-api

假设我具有以下接口:

interface Person {
 name: string;
}

interface Attendee {
 person: Person;
 id: number;
}

我已经弄清楚了如何使用编译器API提取每个属性类型的字符串表示形式,例如:

{ 
 Attendee: {
  person: "Person",
  id: "number"
 }
}

这是我的操作方法:https://github.com/jlkiri/tsx-ray/blob/master/src/index.ts
它是类型检查器的typeToStringgetTypeOfSymbolAtLocation的组合。

但是我想将类似Person的类型解析为其定义,以便获得:

{ 
 Attendee: {
  person: {
   name: "string";
  },
  id: "number"
 }
}

是否可以使用API​​轻松完成此操作,还是必须自己实现逻辑?

0 个答案:

没有答案