Files
scriptc/tests/corpus/8425-array-from-string-nullable.ts
T
Malte UblandClaude Opus 5.5 1a3caa88eb web/text singletons: URLSearchParams ToString, match reads, Array.from
URLSearchParams crossing an implicit ToString (`${sp}`, "" + sp, String(sp))
had no lowering: ensureString now answers sp.toString, the serialized pair
list. Record inits also accept shorthand members (`new URLSearchParams({ model })`)
like the explicit `{ model: model }` spelling.

`re.exec(s)?.index` keeps the optional chain: the read is the match row's
index/input member (the chain lowering binds the guarded receiver first),
so the questionDotToken guard no longer diverts it.

Array.from(s) over a string whose binding the checker narrowed through a
guard read as the narrowed union and fenced; the site type now decides, and
the read is coerced to that string (code points, fresh array).

Corpus 8423-8425 pin all three against Node.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 05:38:28 -07:00

20 lines
757 B
TypeScript

// Array.from over a string the checker narrowed through a guard, and over
// code points (surrogate pairs stay whole), each a fresh array.
const values: (string | undefined)[] = ["abc", undefined, "a\u{1F600}b"];
for (const value of values) {
if (value === undefined) {
console.log("skip");
continue;
}
const chars = Array.from(value);
console.log(chars.length, chars.join("|"));
}
const maybe: string | undefined = "xy";
if (maybe !== undefined) console.log(Array.from(maybe).length);
const plain: string = "q";
console.log(Array.from(plain), Array.from(plain).length);
function guarded(v: string | undefined): boolean {
return v !== undefined && Array.from(v).length > 1;
}
console.log(guarded("ab"), guarded("a"), guarded(undefined));