Files
scriptc/tests/diagnostics/utility-types.ts
T
Chris Tate 8d5b3377aa Represent Dates as objects with identity
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>
2026-10-22 20:33:09 -05:00

18 lines
981 B
TypeScript

// The fences around utility-type record shapes. Utility types over data
// shapes compile (Partial/Record/Pick/Omit/Readonly resolve to ordinary
// record shapes — differential corpus), and STRING and NUMBER index
// signatures over supported value types compile as hybrid shapes (declared
// fields + an overflow map; number keys canonicalize to their JS string
// spelling; function/Map/Set/nested-record values ride the same store —
// differential corpus); what stays rejected:
// - symbol-keyed index signatures (no lowering for symbol keys).
// (Readonly<Date> bindings compile, holding the Date as a checked value.
// Dot access/writes to index-signature keys compile now — the overflow
// path in dot spelling — and self-referential mapped types intern as
// named recursive shapes; differential corpus covers both.)
const bySymbol: { [s: symbol]: string } = {};
console.log(bySymbol);
const stamped: Readonly<Date> = new Date(0);
console.log(stamped.getTime());