In an anonymous class, accessing static
class
property in instance method via this.constructor
is reported as an error (is not an error) [Javascript, but TypeScript checking it]
#60449
Labels
Duplicate
An existing issue was already created
🔎 Search Terms
"class" AND "private" AND ("field" OR "property") AND ("must be declared in an enclosing class" OR "does not exist on type Function") AND "static" AND "this.constructor" AND "private" AND -label:Suggestion
Relevant bugs:
constructor
on the instance type of a class #32452🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play/?filetype=js#code/MYewdgzgLgBA5gUygYQDYEMIRgXhgCgEpcA+AKBkpmAyxgHoAqGAQTHAE8BbEAV2xqZsjejADeFKlOjooAS2AwAxIKwAFAE5yAbrIS4YARgBMAZgDcZSVMoz5ixCloRNOvUXHWbUjUl4awGCgACzkIADoVZ1ddKARLb0oAXytE+CQ0IRi9AFUIOTA4AElIKHQwYAQAWSRgkAATDwk0nz8AoNCI0FKNXmAoEA1I1RctWPivKRSpq27oGGQAGRYAZRWDR0ysIksyOZBUBHDUEDh8GABycM3osfdiHBwLgBoF5bXrjNu3OI9CS32h2OpwIVxuWTucTyBWKpXKlRqIQaHkeLwIYAQAHc3qsVkRCJ8nBCfghoYUSjIKtVasjiP8yEA
💻 Code
Running the above code works. Logs:
🙁 Actual behavior
TypeScript checker says there are errors in the code.
🙂 Expected behavior
No errors from TypeScript checker.
Additional information about the issue
The problem goes away when adding
// @ts-ignore
above the erroring line.Except
when using VSCode¹ locally, the ts-ignore directive does nothing. If I add
// @ts-check
at the top of the file, the ts-ignore directive works as expected.¹ (built-in TypeScript version 5.6.3, Restricted Mode)
The text was updated successfully, but these errors were encountered: