Skip to content

Accessing static private class parameters via this.constructor #48476

Closed
@Araxeus

Description

@Araxeus

Bug Report

🔎 Search Terms

access static private class parameter this.constructor

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about [static, private, classes]
    this probably has always been like this since its a 'new' feature

latest test on 4.7.0-dev.20220302 (nightly)

⏯ Playground Link

Playground link with relevant code

💻 Code

class Test {
    static #staticPrivateField = 'test' ;

    constructor() {
        console.log(
            this.constructor.#staticPrivateField
        )
    }
}

new Test();

🙁 Actual behavior

  1. in Javascript && Typescript (screenshot is .js file in vscode with no tsconfig)
    test.js

if the parameter is only static, it doesn't show the 6133 warning whether its actually used or not
the moment you make it both static + private (#), it suddenly shows the warning.

and then if the parameter is accessed via this.constructor it stills shows the 6133 warning (declared but value never read)

  1. strict check enabled (screenshot is .ts file)
    test.ts
    Property '#staticPrivateField' does not exist on type 'Function'.ts(2339)

🙂 Expected behavior

  1. in javascript using this.constructor.#staticPrivateField should be recognized as accessing the parameter (it does work, and recommended on MDN)
  2. strict check should recognize that this field exist on the class constructor

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions