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

Can't use type this in a static getter, but I can if its a method.. with a generic. But getters don't support generics. #54322

Closed
miguel-leon opened this issue May 19, 2023 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@miguel-leon
Copy link

Bug Report

In the following code

class Base {
	static get Class()/*: this*/ {
		return this;
	}
}
class A extends Base {}
class B extends Base {}

const x = A.Class; // typeof Base 👎 Should be typeof A
const y = B.Class; // typeof Base 👎 Should be typeof B

The type of this is not inferred correctly as it would do if it were an instance method.
But it works as expected if the static getter is changed to a method with generics workaround trickery.

class Base {
	static Class<T>(this: T) {
		return this;
	}
}
class A extends Base {}
class B extends Base {}

const x = A.Class(); // typeof A 🎉
const y = B.Class(); // typeof B 🎉

But then I'm forced to use a method call instead of a property access. I want a property 😥

🔎 Search Terms

static getter this type
There is a similar issue but it doesn't take into account statics.
#35986

🕗 Version & Regression Information

⏯ Playground Link

Playground link A
Playground link B

💻 Code

In the description

🙁 Actual behavior

In the description

🙂 Expected behavior

In the description

@jcalz
Copy link
Contributor

jcalz commented May 19, 2023

Duplicate of #5863

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label May 19, 2023
@microsoft-github-policy-service

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

1 similar comment
@microsoft-github-policy-service

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants