A subclass's method is missing natively when the instance is read back from a Set typed with its base class

Aperta
#4,865 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
58/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, typescript
Ambito
backend, compilers

Direzione di ricerca

Start by tracing how scriptc compiles typed JavaScript Set values and preserves subclass methods; the report reproduces this in dm3.js with allowJs, checkJs and strict. Compare the native output with Node.js and the build without checkJs to narrow down where the method is lost. Done means the compiled reproduction calls Effect._schedule() and prints effect without a runtime error.

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

Descrizione

An override is lost natively when the instance is read back from a Set typed with its base class: calling the method throws TypeError: ... is not a function. The build reports no diagnostic.

Reproduction

dm3.js, built with a tsconfig that has allowJs, checkJs and strict:

class Reactive {
  _schedule() { console.log("reactive"); }
}
class Effect extends Reactive {
  _schedule() { console.log("effect"); }
}
class Dep {
  constructor() {
    /** @type {Set<Reactive>} */
    this._subscribers = new Set();
  }
  /** @param {Reactive} w */
  _add(w) { this._subscribers.add(w); }
  _notify() {
    for (const r of Array.from(this._subscribers)) r._schedule();
  }
}
const d = new Dep();
d._add(new Effect());
d._notify();
Output Exit
Node.js v25.3.0 effect 0
scriptc 0.4.12, 0.4.16 and 0.5.0 Uncaught TypeError: r._schedule is not a function 1

Without checkJs (no JSDoc types reaching the compiler) it prints effect. Neither _schedule is called: the method is missing altogether, not dispatched to the base class.

Environment

Linux x86_64, glibc 2.39, scriptc's linux-x64-gnu packages from npm.

Found through light's probe packages/light/native/probes/p-d-signals.js (a signal library's subscribers kept in a Set of the base class), which fails the same way.

Lingua principale
TypeScript
Stelle
6.7k
Fork
229
Merge medio
14h 29m
PR unite (30g)
787

Preparare l'ambiente

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.

Altre issue di vercel-labs/scriptc

Tutte le issue di vercel-labs/scriptc

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.