ianstormtaylor / superstruct

A simple and composable way to validate data in JavaScript (and TypeScript).

Home Page:https://docs.superstructjs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Runtime error when using create() on superstruct.record with a frozen object

gwisp2 opened this issue · comments

Code

codesandbox

import { record, string } from "superstruct";

const exampleStruct = record(string(), string());
console.log(exampleStruct.create(Object.freeze({ a: "b" })));

Expected result

{ "a": "b" }

Actual result

TypeError
Cannot assign to read only property 'a' of object '#'
at utils.ts#L178

Possible cause

object() creates a Struct whose coercer method creates a copy of the input.
record() creates a Struct with a default coerce method that returns the input without changes.