Skip to content

Commit

Permalink
fix: result freezing after async parse
Browse files Browse the repository at this point in the history
  • Loading branch information
zsilbi committed May 2, 2024
1 parent df00938 commit d06b4d6
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5041,10 +5041,15 @@ export class ZodReadonly<T extends ZodTypeAny> extends ZodType<
> {
_parse(input: ParseInput): ParseReturnType<this["_output"]> {
const result = this._def.innerType._parse(input);
if (isValid(result)) {
result.value = Object.freeze(result.value);
}
return result;
const freeze = (data: ParseReturnType<this["_output"]>) => {
if (isValid(data)) {
data.value = Object.freeze(data.value);
}
return data;
};
return isAsync(result)
? result.then((data) => freeze(data))
: freeze(result);
}

static create = <T extends ZodTypeAny>(
Expand Down

0 comments on commit d06b4d6

Please sign in to comment.