You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Temporal values lose their internal slots when a type with morphs clones its input #1719
Other context you think may be relevant (JS flags, envs, etc.): Node 26 and Chromium, both with native Temporal
🧑💻 Repro
import{type}from"arktype"constT=type({name: "string.trim",at: type.instanceOf(Temporal.Instant)})constout=T.assert({name: " x ",at: Temporal.Now.instant()})out.atinstanceofTemporal.Instant// trueout.at.toString()// TypeError: Method Temporal.Instant.prototype.toString called on incompatible receiver [object Temporal.Instant]
The same happens for undeclared keys that are kept (default "+": "ignore"), and for every Temporal type (PlainDate, ZonedDateTime, Duration, ...). Without a morph (name: "string") the original instance passes through and works.
Cause
When a type has morphs, the input is cloned with _clone in @ark/util/out/clone.js. Temporal constructors are not in builtinConstructors, so a Temporal object is rebuilt with Object.create(Object.getPrototypeOf(input)) plus its own properties. Temporal objects keep their state in internal slots, so the copy passes instanceof but throws on every method call. The usual first sign is a serializer calling toString() and getting an error far away from validation.
Suggested fix
Return Temporal objects as-is in _clone, the same way other built-ins with internal state are returned. They are immutable, so sharing the reference is safe:
A more general option is to clone only plain objects (Object.prototype or null prototype) and arrays, and return any other object unchanged. Any class that keeps its state in private fields (#x) breaks the same way today.
I'd like to work on this. I reproduced the incompatible receiver on current main with Node 26 and the public type(...).assert() API. I plan to preserve native Temporal values when cloning, with focused regression tests and the full pnpm prChecks run before opening a PR. This work is AI-assisted.
Activity
louisss1016 commentedon Nov 4, 2026
I'd like to work on this. I reproduced the incompatible receiver on current main with Node 26 and the public
type(...).assert()API. I plan to preserve native Temporal values when cloning, with focused regression tests and the fullpnpm prChecksrun before opening a PR. This work is AI-assisted.fix(util): return objects with internal slots as is when deep cloning
docs(changelog): describe the November bug fixes and thank their PR a…