Files
scriptc/tests/corpus/2947-set-readonly-seeds.ts
Chris TateandHagege Ruben cc44afb4ee fix: accept readonly tuples as Set seeds (#384)
- Accept supported readonly tuples in static Set constructors while preserving single evaluation and insertion order.
- Add differential coverage and refresh constructor diagnostics.

Fixes #373

Co-authored-by: Hagege Ruben <20857346+HagegeR@users.noreply.github.com>
2026-09-22 21:50:04 -05:00

26 lines
945 B
TypeScript

const words = ["pear", "apple", "pear"] as const;
const named = new Set<string>(words);
console.log(named.size, named.has("apple"), [...named].join(","));
const inferred = new Set(words);
console.log(inferred.size, inferred.has("pear"), [...inferred].join(","));
const readonlyWords: readonly string[] = ["north", "south", "north"];
const fromReadonlyArray = new Set(readonlyWords);
console.log(fromReadonlyArray.size, [...fromReadonlyArray].join(","));
const numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 3] as const;
const fromTuple = new Set<number>(numbers);
console.log(fromTuple.size, [...fromTuple].join(","));
let seedCalls = 0;
function makeSeed() {
seedCalls++;
return ["once", "twice", "once"] as const;
}
const fromCall = new Set<string>(makeSeed());
console.log(seedCalls, fromCall.size, [...fromCall].join(","));
const direct = new Set(["red", "blue", "red"] as const);
console.log(direct.size, [...direct].join(","));