Skip to content

Arktype doesn't work with @date-fns/utc UTCDate class. #1568

Closed

Description

@stepaniukm

When passing through the UTCDate and trying to do .toISOString() it blows up with an error Uncaught TypeError: Method Date.prototype.toISOString called on incompatible receiver [object Object]. I wouldn't file an issue, as UTCDate does some dirty tricks underneath, but it works for example in the latest zod, so probably worth to look into it. If you guys could guide me through the possible causes I would be happy to contribute. Thanks for help in advance.

🔎 Search Terms

UTCDate, @date-fns/utc

🧩 Context

  • ArkType version: 2.1.29
  • TypeScript version (5.1+): 5.9.3

🧑‍💻 Repro

https://stackblitz.com/edit/vitejs-vite-hh6wmtg8?file=src%2Fmain.ts

Activity

  1. potatohoney-p commented on Oct 22, 2026

    @potatohoney-p

    @stepaniukm, I saw your offer to contribute, and this issue is assigned to @ssalbdivad. Before duplicating any work, is a patch already underway?

    This still reproduces with arktype 2.2.9 / @ark/util 0.56.8 on Node 24.19.0, even without date-fns:

    import { type } from "arktype"
    class MyDate extends Date {}
    
    const toIso = type(["Date", "=>", value => value.toISOString()])
    toIso.assert(new MyDate("2026-01-02T03:04:05.000Z"))

    It throws Method Date.prototype.toISOString called on incompatible receiver [object Object]. Using a plain Date succeeds. A second-level subclass and UTCDate also fail.

    The same cloning path on main at cfded1ae9a38b1da527790bb5698ab2d58d6783d handles the exact Date constructor separately, but subclasses reach Object.create, which preserves their prototype without Date's internal timestamp slot.

    A narrow guard could preserve Date subclasses by reference, but that aliases the input, so a mutating morph could change the original. Invoking arbitrary subclass constructors is not generically safe, and re-prototyping a new Date cannot restore subclass private fields.

    What cloning contract should Date subclasses follow? I’d like to agree on that before preparing a focused regression test and fix, rather than assume pass-through or plain-Date conversion is intended.

  2. ssalbdivad commented on Oct 22, 2026

    @ssalbdivad
    Member

    @potatohoney-p this will be fixed in our next release!

  3. ssalbdivad commented on Nov 18, 2026

    @ssalbdivad
    Member

    Fixed in 3.0.0-beta.0 (#1728). Try it with npm i arktype@next.

  4. moved this from To do to Done (merged or closed) in arktypeioon Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

  • Status
    Done (merged or closed)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions