Skip to content

Stack overflow for infinitely recursive anonymous type #3309

Closed
@JsonFreeman

Description

@JsonFreeman
function foo<T>() {
    var z = foo<typeof y>();
    var y: {
        y2: typeof z
    };
    return y;
}


function bar<T>() {
    var z = bar<typeof y>();
    var y: {
        y2: typeof z;
    }
    return y;
}

var a = foo<number>();
var b = bar<number>();
a = b;

Because the type parameter T is in scope when we encounter the anonymous type for y, a new type is created for the type of y. But each time foo/bar is called, yet a different type for y is created inside that call!

@ahejlsberg and I are leaning towards a solution that classifies such anonymous types (with type parameters in scope) as References, and give them targets. That way, isDeeplyNestedGeneric will bottom out and detect recursion.

We may need a similar mechanism in the display writer.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions