ianstormtaylor / superstruct

A simple and composable way to validate data in JavaScript (and TypeScript).
https://docs.superstructjs.org
MIT License
6.97k stars 223 forks source link

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

Closed gwisp2 closed 2 months ago

gwisp2 commented 2 years ago

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.