Skip to content

JSDoc: property access within static initialization block of @extends annotated class from different file #58943

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

Open
Daniel-Knights opened this issue Jun 20, 2024 · 1 comment · May be fixed by #59817
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@Daniel-Knights
Copy link

Daniel-Knights commented Jun 20, 2024

🔎 Search Terms

"jsdoc class @extends", "static initialization block", "static properties/methods", "class extends", "class is referenced directly or indirectly in its own base expression"

🕗 Version & Regression Information

  • Static initialization blocks don't seem to be supported on versions <= 4.3.5
  • From 4.4.2 to 4.6.4 everything seems to work fine - types are correct and no linting errors
  • Every version from 4.7.2 onwards has the behaviour described in this issue

⏯ Playground Link

No response

💻 Code

a.js:

export class A {
  static a() {}
}

b.js:

// @ts-check
import { A } from "./a";

/**
 * @extends A
 */
export class B extends A { // 'B' is referenced directly or indirectly in its own base expression.ts(2506)
  static {
    B.a(); // Property 'a' does not exist on type 'typeof B'. ts(2339)
  }

  constructor() {
    super();

    B.a(); // Property 'a' does not exist on type 'typeof B'. ts(2339)
  }

  b() {
    B.a(); // Property 'a' does not exist on type 'typeof B'. ts(2339)
  }

  c = () => {
    B.a(); // Property 'a' does not exist on type 'typeof B'. ts(2339)
  };

  static d() {
    B.a(); // Property 'a' does not exist on type 'typeof B'. ts(2339)
  }

  get e() {
    B.a(); // Property 'a' does not exist on type 'typeof B'. ts(2339)

    return;
  }

  set e(value) {
    B.a(); // Property 'a' does not exist on type 'typeof B'. ts(2339)
  }
}

🙁 Actual behavior

  • Linting error under extending class's name: 'B' is referenced directly or indirectly in its own base expression..
  • Linting error/unknown type for any use of B.a().

🙂 Expected behavior

B.a() type is correct across files with no linting errors.

Additional information about the issue

  • Removing @extends fixes the issue
  • Removing B.a() from the static block fixes the issue
  • Defining A in the same file fixes the issue

Possibly related to #51786.

@Daniel-Knights Daniel-Knights changed the title JSDoc: property access within static initialization block of @extends annotated class JSDoc: property access within static initialization block of @extends annotated class from different file Jun 20, 2024
@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Jun 21, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jun 21, 2024
@Andarist
Copy link
Contributor

Andarist commented Sep 1, 2024

bisects to #44969

JSDoc is bound as a child of its associated declaration and static block declarations are bound as immediately invoked when binding the declaration itself. So this @extends has a flow node pointing to the body of the static block. So when the class' type is requested it tries to resolve the flow node of the super class it received, which leads to resolving the type of the class' in the static block (this bit is circular here).

It's a bug, I'm just saying what happens internally that it's there 😉

@Andarist Andarist linked a pull request Sep 1, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants