microsoft / microsoft/TypeScript

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

Aperta
#58,943 1 commento 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Bug Domain: JSDoc Help Wanted
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Riproduci il problema con i file a.js e b.js forniti, concentrandoti sull’annotazione @extends, sul blocco di inizializzazione statica e sugli utilizzi di B.a(). Confronta le diagnosi e il tipo dedotto tra le versioni descritte; il lavoro è completato quando B estende A senza l’errore di classe base circolare e B.a() è tipizzato correttamente in ogni posizione mostrata.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.