或者有没有办法从声明typescript文件(d.ts)中获取函数返回类型和参数类型,方法签名的语句包括函数返回类型和类型注释中的参数类型 . 例如:
loadViewModel? (componentName: string, viewModelConfig: any, callback: (result: any) => void): void;
函数返回类型和字符串是void,任何作为参数类型 .
我的意思是如何使用typescript服务库获取声明typescript文件中的返回类型的函数 .
这有几个步骤:
锅炉板:安装语言服务并使用 getProgram
getProgram
使用访问者获取源文件以获取 function 声明 . 更多:https://basarat.gitbooks.io/typescript/content/docs/compiler/ast-tip-children.html
function
对于每个找到的项目,使用类型检查器获取其关联类型:https://basarat.gitbooks.io/typescript/content/docs/compiler/checker.html
我已经创建了一个IDE来试验编译器的想法:http://alm.tools/
1 回答
这有几个步骤:
锅炉板:安装语言服务并使用
getProgram
使用访问者获取源文件以获取
function
声明 . 更多:https://basarat.gitbooks.io/typescript/content/docs/compiler/ast-tip-children.html对于每个找到的项目,使用类型检查器获取其关联类型:https://basarat.gitbooks.io/typescript/content/docs/compiler/checker.html
更多
我已经创建了一个IDE来试验编译器的想法:http://alm.tools/