mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-28 06:53:42 +08:00
Arrays the checker types with unknown elements are stored checked-dynamic, and their methods dispatch on the runtime array. splice was missing from that dispatch table, so unknown[] receivers refused it, including generic bodies instantiated at unknown (pool.splice(i, 1) in a sample<T> helper gets such an instantiation once a program has a dynamic tier). The runtime's dynInvoke already implements splice; the table now names it, and arrays of unknown elements take the dispatch from the array-method lowering. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
15 lines
657 B
TypeScript
15 lines
657 B
TypeScript
// Methods on arrays of unknown elements, which are stored checked-dynamic:
|
|
// direct `unknown[]` bindings and generic bodies instantiated at `unknown`.
|
|
const values: unknown[] = [1, "two", 3, { four: 4 }];
|
|
const removed = values.splice(1, 2);
|
|
console.log(values, removed, removed.length);
|
|
values.splice(1, 0, "inserted", null);
|
|
console.log(values, values.indexOf(null), values.includes("inserted"));
|
|
console.log(values.slice(1).reverse(), values.join("|"));
|
|
|
|
function takeAt<T>(items: readonly T[], index: number): T[] {
|
|
const pool = [...items];
|
|
return pool.splice(index, 1);
|
|
}
|
|
console.log(takeAt([10, 20, 30], 1), takeAt<unknown>([true, "x", 7], 2));
|