Skip to content

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

@gwisp2

Description

@gwisp2

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions