Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Records containing non-serializable values (e.g. Temporal, Decimal) throw DataCloneError during updates

Open
#378 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
72/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
backend

Research direction

Start at CollectionOptions and the core Collection update path where structuredClone copies records. Review the linked working branch and its tests for the proposed behavior, then verify that the default preserves structuredClone behavior while a supplied clone function is used during updates.

Written by the indexing model from the issue text.

Description

Problem

structuredClone is used internally to copy records before updates, but it throws a DataCloneError for non-serializable values like class instances with function own-properties (e.g. Temporal.PlainDate, Decimal from decimal.js). There's currently no way to provide an alternative cloning strategy.

Proposal

Add an optional clone property to CollectionOptions that allows users to provide a custom clone function (e.g. cloneDeep from es-toolkit). It defaults to structuredClone to preserve existing behavior.

const collection = new Collection({
  schema,
  clone: cloneDeep, // just an example, cloneDeep maintains references of non-serializable types, custom strategy may be preferred
})

Notes

The persist and sync extensions rely on JSON.stringify and serializeRecord respectively, so records must still be serializable when using those extensions. The clone option only affects how records are copied during updates in the core collection.

Suggested Implementation

I have a working branch with tests if you'd like me to open a PR: https://github.com/danmcdaid/data/tree/feat/custom-clone-option

Dominant language
TypeScript
Stars
1.1k
Forks
66
Avg merge
3m
Merged PRs (30d)
2

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mswjs/data

All issues in mswjs/data

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.