-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Referencing this
from a static class field
#36267
Comments
Sounds like you want #5863, but if I recall correctly, the problem is that we don't assume the static side of one class is substitutable for another because then every subclass construct signature would have to be assignable to the constructor in the superclass. |
AFAICT, this is simpler. In first example above, Another example: class A {
// Legal in JS, not allowed in TS:
static thisIsA = (this === A);
}
class B extends A {}
console.log(B.thisIsA); // true |
So you want "Monomorphic |
Probably? 🤔 |
Thank you for finding this @rauschma! It's not just the type checking that's wrong. The emit is corrupting legit ESnext code. Playground class C {
static self = this;
} ...becomes... class C {}
C.self = this; |
Right! Should be done via definition, not assignment. |
Actually that bit is handled fine via the option Interestingly this bug goes away if |
@sandersn can you look at the emit thing (described lower in comments) ? |
Note that the classic, non-spec-compliant emit has been wrong since at least 2.4: https://www.typescriptlang.org/play/?ts=2.4.1#code/MYGwhgzhAEDCD2J4CdoFMAeAXNA7AJjAKK4CuAtgJYBmAntAN4CwAUNNBFmFpcNMmnzQAvNFxoA7nEQoAFAEoA3K3aduvaCjC4A5mhFjJ0pMgXK2HLjz600IJFNHipCE2ZWX1fHQLwHnxnJKHmrW0ABGIKT6TkauQeaqVhoADqTIKSAxhi4ypsEWoRoA+gZYABaUEAB0oPAQaCQUZtAA9K3QACq0KWgAysDIlClYAFyByLVIDU3kCqwAvkA |
I did (1) in #36781. @rbuckton can you think of any problems with changing |
(2) is getting complicated fast -- and I still haven't thought about decorated classes. I'm going to move this to 4.0 since it's unlikely a finished PR would be safe to ship in the RC anyway. |
Any progress? It's affect #42986 and #43092 at least.
from #36781 (review) It's might good for now. |
TypeScript Version: Nightly Playground
The following code (Playground link) is legal in JavaScript, but produces a static error in TypeScript:
Practical use case – my library Enumify for enums:
The text was updated successfully, but these errors were encountered: