Narrowed-to-never string-literal union passed to a `never` parameter: SC1090 "'string' values where 'number' is expected"

Đã đóng
#2,158 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ó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
72/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ệ
node.js, typescript
Lĩnh vực
backend, compilers

Hướng nghiên cứu

Start by running the provided repro.ts example with scriptc 0.4.4 and compare it with Node’s type stripping; the report identifies string literal union narrowing to never as the failing case. Then trace how the compiler lowers that narrowed value and how it checks the argument passed to unreachable. Done when the example compiles and the reported number union and typeof narrowing cases still behave as described.

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

Mô tả

Disclosure: this report was produced with the help of an AI agent (Claude Code). The agent reduced the problem from a real codebase to the repro below, ran every command shown, and drafted this text; a human reviewed it and decided to file it. The commands and outputs are real runs.

Environment: scriptc 0.4.4 (@scriptc/cli-linux-x64-gnu), Linux x86_64, Node 22.22.0. Reference behaviour from node --experimental-strip-types.

function unreachable(_: never): never { throw new Error("unreachable"); }
type K = "a" | "b";
function f(k: K): number {
  if (k === "a") return 1;
  if (k === "b") return 2;
  return unreachable(k);
}
console.log(f(Date.now() > 0 ? "a" : "b"));
$ scriptc build repro.ts -o t
repro.ts:6:22 - error SC1090: 'string' values where 'number' is expected is not supported yet
$ node --experimental-strip-types repro.ts
1

Expected: compiles (the standard exhaustiveness-check idiom).

Observations (all run 2026-10-24)

  • unreachable(k as never) fails the same way.
  • The same program with a number-literal union (type K = 1 | 2) compiles and prints 1.
  • typeof-narrowing a string | number to never compiles and prints 1.
  • So the failure seems specific to a string-literal union narrowed to never, which appears to be lowered as number.

Context: vjuga FunctionUtils.unreachable(_: never): never, used for exhaustive switch/if chains over string-literal unions.

Ngôn ngữ chính
TypeScript
Star
6.4k
Fork
204
Merge trung bình
7 giờ 35 phút
Pull request đã merge (30 ngày)
873

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.