Skip to content

ts.TypeChecker.typeToTypeNode goes in infinite loop eating up CPU and Memory. #29564

Closed
@abhijitparkhi1983

Description

@abhijitparkhi1983

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.

SEA3DAmmo.txt

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions