microsoft / microsoft/TypeScript

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

Open
#58,943 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: JSDoc Help Wanted
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

🔎 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the provided a.js and b.js files, focusing on the @extends annotation, the static initialization block, and uses of B.a(). Compare the diagnostics and inferred type across the versions described; done means B extends A without the circular-base error and B.a() is correctly typed in each shown location.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.