Files
scriptc/tests/corpus/6521-tuple-spread-into-array.ts
T
Malte UblandClaude Opus 5.5 db68255cbc Read typescript-go's unreadable match-or-empty unions through their widened members; compile tuple spreads, Stats arrays, primitive then handlers and fielded error inspection
- `s.match(re) ?? []` / `|| []` made typescript-go's API panic whenever the
  union's members were serialized (the empty literal is a tuple clone
  without tuple data), poisoning the statement with SC0004. The members
  of the union's widened type are readable and describe the same values,
  so constituent reads answer with them; the empty tuple beside a match
  array is one of its values. `checker-panic-tuple.ts` compiles and moves
  to the corpus.
- Spreading a fixed tuple into an array literal copies its positions
  into the literal's element type.
- fs.Stats values are an array element kind, so `Promise.all` over
  `stat()` promises and `Stats[].reduce` compile.
- `.then(String)`, `.then(Number)` and `.then(Boolean)` over a number or
  boolean settled value convert it through an interned closure.
- Inspecting (util.format, %s, util.inspect) an Error-typed value whose
  runtime class declares fields prints the stackless base with Node's
  constructor-name header (`[Bailable [Error]: m]`) and the own
  properties, `[Bailable [Error]: m] { bail: true }`; it was refused. A
  subclass whose own fields cannot render (functions, or a field Node's
  error inspector treats specially) throws a named refusal on its own
  instances only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 05:17:42 -07:00

13 lines
600 B
TypeScript

// Spreading a fixed tuple into an array literal copies its positions in
// order into the literal's element type.
const SCRIPT_FILES: [string, string, string, string, string] = ["a.ts", "a.mts", "a.cts", "a.js", "a.mjs"];
const DATA_FILES = ["a.json"];
const files = [...SCRIPT_FILES, ...DATA_FILES];
console.log(files.length, files.join(","));
const PAIR = ["x", "y"] as const;
const more: string[] = [...PAIR, "z", ...SCRIPT_FILES.slice(0, 1)];
console.log(more);
const numbers: [number, number, number] = [1, 2, 3];
const widened: (number | string)[] = [...numbers, "end"];
console.log(widened);