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

Đang mở
#4,865 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
58/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
javascript, typescript
Lĩnh vực
backend, compilers

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
6.7k
Fork
229
Merge trung bình
14 giờ 29 phút
Pull request đã merge (30 ngày)
787

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của vercel-labs/scriptc

Tất cả issue của vercel-labs/scriptc

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.