Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gwisp2 opened this issue Aug 17, 2022 · 0 comments · May be fixed by #1151
Open

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

gwisp2 opened this issue Aug 17, 2022 · 0 comments · May be fixed by #1151
Labels
bug ♥ help please Issues that we'd love help solving

Comments

@gwisp2
Copy link

gwisp2 commented Aug 17, 2022

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.

@ianstormtaylor ianstormtaylor added bug ♥ help please Issues that we'd love help solving labels Sep 19, 2022
@arturmuller arturmuller linked a pull request Nov 20, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug ♥ help please Issues that we'd love help solving
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants