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

Đã đóng
#2,159 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

Một pull request liên quan đã được merge.

  • #2319 của @ctate — đã merge

Đá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
53/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
compilers

Hướng nghiên cứu

Start by tracing how the compiler lowers string-literal unions narrowed to never and compares the resulting argument type with a never parameter. Use the supplied repro with scriptc build repro.ts -o t as the failing case, then compare it with the number-literal union and typeof narrowing examples. Done means the string-literal exhaustiveness example compiles while those comparison cases continue to 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ờ 44 phút
Pull request đã merge (30 ngày)
879

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.