如何确定TypeScript.Expression对象的结果类型?

如何确定TypeScript.Expression对象的结果类型?,typescript,tslint,Typescript,Tslint,使用TypeScript抽象语法树时,如何确定TypeScript.Expression对象的结果类型 我正在使用TSLint并尝试查找setTimeout调用,这些调用没有将Function类型的对象作为第一个参数传递。例如,在下面的代码中,我想知道调用了setTimeout,并且第一个参数是一个函数 // function that produces a function var createFunction : () => (() => void) = () => {};

使用TypeScript抽象语法树时,如何确定TypeScript.Expression对象的结果类型

我正在使用TSLint并尝试查找setTimeout调用,这些调用没有将Function类型的对象作为第一个参数传递。例如,在下面的代码中,我想知道调用了setTimeout,并且第一个参数是一个函数

// function that produces a function
var createFunction : () => (() => void) = () => {}; 
// result of createFunction() should be of type function
setTimeout(createFunction());
AST排列如下:

  • setTimeout->TypeScript.CallExpression
  • createFunction()->TypeScript.Expression
我曾尝试使用LanguageService来确定表达式的类型,但以下API都不能满足我的需要:

  • languageServices.getQuickInfoAtPosition
  • languageServices.getDefinitionAtPosition
  • languageServices.getTypeDefinitionAtPosition

有什么想法吗?

语言服务本身不公开这些信息

可以使用类型检查器执行此操作。从
createProgram
中获得
程序
对象后,编写:

        let typeChecker = program.getTypeChecker();
        let type = typeChecker.getTypeAtLocation(node);