Skip to content

Instantiation expression inside nested classes produces unexpected circular reference errorΒ #52892

Open
@whzx5byb

Description

@whzx5byb

Bug Report

πŸ”Ž Search Terms

instantiation expression nested class

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

class A<T = number> {
    //static { type _<T extends A = A> = 0 }
    //^ will work when uncomment it?

    value!: T;
    child!: InstanceType<typeof A.B<A<T>>>

    static B = class B<T extends A = A> {
        parent!: T;
    } 
}

var a = new A
a.child.parent.value
//              ^?

πŸ™ Actual behavior

Shows an error 'child' is referenced directly or indirectly in its own type annotation..

However, when uncommenting // static {...} it will work only in playground.
In VSCode it still shows the error above.

πŸ™‚ Expected behavior

a.child.parent.value is number

Workaround

A workaround is remove the default type for class B<T>. The code below works well, also, only in playground. In my VSCode(5.0.0-dev.20230216) it still breaks unfortunately.

class A<T extends number = number> {
    value!: T;
    child!: InstanceType<typeof A.B<A<T>>>

    static B = class B<T extends A> {
        parent!: T;
    }  
}

var a = new A
a.child.parent.value
//                ^? number

Metadata

Metadata

Assignees

Labels

Fix AvailableA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions