diff --git a/package.json b/package.json index d68c313..5bffa9c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "validated-extendable", - "version": "7.2.11", + "version": "7.2.12", "description": "A library that allows you to define classes extending zod schemas to avoid boilerplate code.", "exports": { ".": { diff --git a/src/index.ts b/src/index.ts index e9bf6fa..fdfade4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -40,8 +40,7 @@ export const Validated = < const validatedValue = schema.parse(value); const wrapValue = !isObject(validatedValue) || options?.wrapValue; const _this = wrapValue ? { value: validatedValue } : validatedValue; - Object.setPrototypeOf(_this, this); - return _this; + return Object.create(this, Object.getOwnPropertyDescriptors(_this)); } as unknown as ValidatedConstructor< Schema, Options extends { wrapValue: true } ? true : IsPrimitive> @@ -88,8 +87,9 @@ export const ValidatedMutable = < const validatedValueProxy = isObject(validatedValue) ? makeValidatedValueProxy(value)(validatedValue) : validatedValue; - const _this = new Proxy( - { value: validatedValueProxy }, + const _this = { value: validatedValueProxy }; + return new Proxy( + Object.create(this, Object.getOwnPropertyDescriptors(_this)), { set(object, propertyName, newValue) { if (propertyName !== "value") { @@ -103,12 +103,11 @@ export const ValidatedMutable = < }, }, ); - Object.setPrototypeOf(_this, this); - return _this; } - const _this = makeValidatedValueProxy(value)(validatedValue); - Object.setPrototypeOf(_this, this); - return _this; + const _this = validatedValue; + return makeValidatedValueProxy(value)( + Object.create(this, Object.getOwnPropertyDescriptors(_this)), + ); } as unknown as ValidatedMutableConstructor< Schema, Options extends { wrapValue: true } ? true : IsPrimitive>