microsoft / microsoft/TypeScript

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

Offen
#58,943 1 Kommentar 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bug Domain: JSDoc Help Wanted
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.4k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Reproduziere das Problem mit den bereitgestellten Dateien a.js und b.js und konzentriere dich dabei auf die @extends-Annotation, den statischen Initialisierungsblock und die Verwendungen von B.a(). Vergleiche die Diagnosen und den abgeleiteten Typ über die beschriebenen Versionen hinweg; abgeschlossen ist die Aufgabe, wenn B A erweitert, ohne dass der Fehler wegen einer zirkulären Basisklasse auftritt, und B.a() an jeder gezeigten Stelle korrekt typisiert ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, typescript
Bereich
compilers
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.