Skip to content
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

Property disappears when matching type parameter name in subclass #56620

Closed
molisani opened this issue Nov 30, 2023 · 4 comments · Fixed by #56626
Closed

Property disappears when matching type parameter name in subclass #56620

molisani opened this issue Nov 30, 2023 · 4 comments · Fixed by #56626
Labels
Bug A bug in TypeScript
Milestone

Comments

@molisani
Copy link
Contributor

molisani commented Nov 30, 2023

🔎 Search Terms

ts2339, "property does not exist on type", "property matches type parameter"

🕗 Version & Regression Information

  • This changed between versions 5.2.2 and 5.3.2

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.3.2#code/MYGwhgzhAEBCkFNoG8C+BuAUJg9D6AcgPbQBGi0okEANNAC4CeADks2AE5gC2C9CHaAHcAlvQAW0CDyQA7GdAC00AOpEOAawiYEAD2br6lcFGgBhAIwAeACoA+FJmjPoNgFzRZAV26kBWF0oiWQh6Di9genUACndPHz8OAEpHQMCJEQgAOhtoAF5XAJdUTBLcfHgIJCooOiZWaHYuXn5BUQkpBXleJWgAESIECFkAciMhdQ0dfUNjanMAJlsHPX5ZABMYSqRkJxc4719-PedgYNDwyJiDhIEU3bSXCC9WDmikoseM7NyCm0-oCUSkA

💻 Code

class Base {};

// No base class, type parameter with same name - Works
export class C1<T> {
    T: number;
    constructor(T: number) {
        this.T = T;
    }
}

// Base class, type parameter with same name - Doesn't work
export class C2<T> extends Base {
    T: number;
    constructor(T: number) {
        super();
        this.T = T; // Property 'T' does not exist on type 'C2<T>'.(2339)
    }
}

🙁 Actual behavior

Property 'T' does not exist on type 'C2<T>'.(2339)

TypeScript does not recognize property T on class C2 but no issue on class C1.

🙂 Expected behavior

No type error, property should be found as expected for both C1 and C2.

Additional information about the issue

This is not an issue if the class does not extend another class, or if the type parameter does not match the property. The property is also not defined on the parent class.

@RyanCavanaugh
Copy link
Member

I'm incredibly excited to see what commit caused this...

@RyanCavanaugh
Copy link
Member

#55252

@RyanCavanaugh
Copy link
Member

@molisani do you have a reasonable workaround on your end, or do you need a 5.3 patch?

@molisani
Copy link
Contributor Author

@molisani do you have a reasonable workaround on your end, or do you need a 5.3 patch?

This only affects one of our projects and changing either the property name or the type parameter resolves it for now so I don't think an immediate patch is necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants