Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
whzx5byb opened this issue Feb 21, 2023 · 1 comment Β· May be fixed by #59607
Open

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

whzx5byb opened this issue Feb 21, 2023 · 1 comment Β· May be fixed by #59607
Assignees
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status. Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@whzx5byb
Copy link

whzx5byb commented Feb 21, 2023

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
@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Feb 22, 2023
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 5.1.0 milestone Feb 22, 2023
@jakebailey
Copy link
Member

I suspect #52813 is related. We'll see.

@RyanCavanaugh RyanCavanaugh added the Rescheduled This issue was previously scheduled to an earlier milestone label Mar 4, 2024
@Andarist Andarist linked a pull request Aug 12, 2024 that will close this issue
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status. Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants