mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-01 07:33:12 +08:00
A Date is a refcounted object holding its time value, shared with the checked-dynamic Date handle, so it keeps its identity through unknown. Dates compile in arrays (includes, indexOf, lastIndexOf, join, default sort by toString() text), in Date | undefined and Date | null slots, as Map and Set keys and values, in index signatures, and in records, tuples, class fields, closures, promises and generators. === compares identity, relational operators compare time values, new Date(date) makes a new Date, and JSON.stringify writes toJSON(). Closes #225 Co-authored-by: Max B <max@tfq.at>
47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
// SC2009: supported shapes over a component type outside its slot — the
|
|
// container is not the blocker, and each message names the component.
|
|
|
|
// Boolean Map keys remain outside the supported key domain.
|
|
const byFlag = new Map<boolean, string>();
|
|
console.log(byFlag);
|
|
|
|
// Map values have no slot for URLSearchParams.
|
|
const queries = new Map<string, URLSearchParams>();
|
|
console.log(queries);
|
|
|
|
// Boolean Set elements remain outside the supported element domain.
|
|
const flags = new Set<boolean>();
|
|
console.log(flags);
|
|
|
|
// Arrays hold Map elements; retain the accepted adjacent form.
|
|
const rows: Map<string, number>[] = [];
|
|
console.log(rows);
|
|
|
|
// Nullable Maps compile and remain as working context.
|
|
function report(maybe: Map<string, number> | undefined): number {
|
|
return maybe === undefined ? 0 : maybe.size;
|
|
}
|
|
console.log(report(undefined));
|
|
|
|
// Typed rest values now compile; retained here as working context for the
|
|
// component-type failures below.
|
|
const sum = (...xs: number[]): number => xs.length;
|
|
const storedSum = sum;
|
|
console.log(storedSum(1, 2));
|
|
|
|
// A function's return type carries the failure. The value arrives through
|
|
// a cast, not an ambient declare (a declare-rooted chain would compile to
|
|
// Node's ReferenceError at the root instead).
|
|
const makeWeak = (0 as unknown) as () => WeakRef<object>;
|
|
const storedMake = makeWeak;
|
|
console.log(storedMake());
|
|
|
|
// A record member's type carries the failure.
|
|
interface Holder {
|
|
label: string;
|
|
cache: WeakRef<object>;
|
|
}
|
|
const held = (0 as unknown) as Holder;
|
|
const kept = held;
|
|
console.log(kept.label);
|