Description
TypeScript Version: 3.2.2
Search Terms:
ts.TypeChecker.typeToTypeNode,
ts.TypeLiteralNode,
ts.NodeBuilderFlags.NoTruncation
Description:
We are trying to use typescript compiler for getting the type of ObjectLiteralExpression and for the purpose we utilize following code:
getApparentTypeForObjectLiteralExpression(node : ts.Node) : {type : ts.Type, typeNode : ts.TypeNode} {
let type : ts.Type = this.checker.getTypeAtLocation(node);
let typeNode = this.checker.typeToTypeNode(type, undefined, ts.NodeBuilderFlags.NoTruncation);
if(ts.isTypeLiteralNode(typeNode))
{
var memberCount = typeNode.members.length;
var name : string;
typeNode.members.forEach(member => {
name += member.name;
name += " , ";
});
}
return {type, typeNode}
}
When we run the above code over the attached file SEA3DAmmo.txt (rename file to SEA3DAmmo.js), the line this.checker.typeToTypeNode goes into infinite loop and the application consumes high CPU and Memory and the call does not return back atall.
This is an absolute blocker, may be i am doing some mistake.
I also tried running with following options:
this.checker.typeToTypeNode(type, node, ts.NodeBuilderFlags.NoTruncation);
or
this.checker.typeToTypeNode(type, node.parent, ts.NodeBuilderFlags.NoTruncation);
Expected behavior:
It should return value and should not go in infinite loop.