Q:

How to get generic type from a method signature return type

Given a typescript file like:
export interface Service {
  execute(): Promise<number>;
}

How can I get a list of all methods and their return types. 
Currently I'm trying to use the typescript compiler API to achieve this.  But I'm having difficulty with 'generics'. 
Thus far I've the following code, but I can't figure out how to get the 'number' type of the Promise. 
let program = ts.createProgram(['./something.ts'], {});
let typeChecker = program.getTypeChecker();

for (const sourceFile of program.getSourceFiles()) {
  sourceFile.forEachChild((node: ts. Node) => {
    // I filter to make sure I've the InterfaceDeclaration. 

    var interfaceDeclaration: ts. InterfaceDeclaration = node;
    interfaceDeclaration.forEachChild((child) => {    
      // I make sure it is a Method Signature. 

      var method : ts. MethodSignature = child;
      var signature = typeChecker.getSignatureFromDeclaration(method);
      var returnType = typeChecker.getReturnTypeOfSignature(signature);
      var parameters = method.parameters;

      console.log("name: " + method.name.getText());
      console.log("return type: " + returnType.symbol.getName());
      console.log("parameters: " + parameters);
    })
  })
}

Which prints:
  name: execute
  return type: Promise
  parameters: []

How can I get the number type in the Promise? 

A:

The type in this case is a ts. TypeReference, so the number type in the promise will be in the typeArguments array property of the type. 
const returnType = typeChecker.getReturnTypeOfSignature(signature) as ts. TypeReference;

console.log(returnType.typeArguments![0]);

