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

オープン
#4,865 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
58/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
javascript, typescript
領域
backend, compilers

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
TypeScript
スター
6.7k
フォーク
229
平均マージ
14時間 29分
マージ済み PR(30日)
787

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

vercel-labs/scriptc のほかの issue

vercel-labs/scriptc の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。