Skip to content

Commit 29e4973

Browse files
authored
refactor: remove unnecessary assertion (#4672)
1 parent 8e20a20 commit 29e4973

File tree

8 files changed

+20
-20
lines changed

8 files changed

+20
-20
lines changed

packages/zod/src/v3/helpers/parseUtil.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const makeIssue = (params: {
2828
const maps = errorMaps
2929
.filter((m) => !!m)
3030
.slice()
31-
.reverse() as ZodErrorMap[];
31+
.reverse();
3232
for (const map of maps) {
3333
errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
3434
}
@@ -80,7 +80,7 @@ export function addIssueToContext(ctx: ParseContext, issueData: IssueData): void
8080
ctx.schemaErrorMap, // then schema-bound map if available
8181
overrideMap, // then global override map
8282
overrideMap === defaultErrorMap ? undefined : defaultErrorMap, // then global default map
83-
].filter((x) => !!x) as ZodErrorMap[],
83+
].filter((x) => !!x),
8484
});
8585
ctx.common.issues.push(issue);
8686
}

packages/zod/src/v3/helpers/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export namespace util {
1818
for (const item of items) {
1919
obj[item] = item;
2020
}
21-
return obj as any;
21+
return obj;
2222
};
2323

2424
export const getValidEnumValues = (obj: any): any[] => {

packages/zod/src/v3/types.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2804,7 +2804,7 @@ export class ZodObject<
28042804
* @deprecated
28052805
*/
28062806
deepPartial(): partialUtil.DeepPartial<this> {
2807-
return deepPartialify(this) as any;
2807+
return deepPartialify(this);
28082808
}
28092809

28102810
partial(): ZodObject<{ [k in keyof T]: ZodOptional<T[k]> }, UnknownKeys, Catchall>;
@@ -3072,7 +3072,7 @@ const getDiscriminator = <T extends ZodTypeAny>(type: T): Primitive[] => {
30723072
return type.options;
30733073
} else if (type instanceof ZodNativeEnum) {
30743074
// eslint-disable-next-line ban/ban
3075-
return util.objectValues(type.enum as any);
3075+
return util.objectValues(type.enum);
30763076
} else if (type instanceof ZodDefault) {
30773077
return getDiscriminator(type._def.innerType);
30783078
} else if (type instanceof ZodUndefined) {
@@ -3309,7 +3309,7 @@ export class ZodIntersection<T extends ZodTypeAny, U extends ZodTypeAny> extends
33093309
status.dirty();
33103310
}
33113311

3312-
return { status: status.value, value: merged.data as any };
3312+
return { status: status.value, value: merged.data };
33133313
};
33143314

33153315
if (ctx.common.async) {
@@ -3833,7 +3833,7 @@ export class ZodFunction<Args extends ZodTuple<any, any>, Returns extends ZodTyp
38333833
path: ctx.path,
38343834
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), defaultErrorMap].filter(
38353835
(x) => !!x
3836-
) as ZodErrorMap[],
3836+
),
38373837
issueData: {
38383838
code: ZodIssueCode.invalid_arguments,
38393839
argumentsError: error,
@@ -3847,7 +3847,7 @@ export class ZodFunction<Args extends ZodTuple<any, any>, Returns extends ZodTyp
38473847
path: ctx.path,
38483848
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), defaultErrorMap].filter(
38493849
(x) => !!x
3850-
) as ZodErrorMap[],
3850+
),
38513851
issueData: {
38523852
code: ZodIssueCode.invalid_return_type,
38533853
returnTypeError: error,
@@ -4115,23 +4115,23 @@ export class ZodEnum<T extends [string, ...string[]]> extends ZodType<T[number],
41154115
for (const val of this._def.values) {
41164116
enumValues[val] = val;
41174117
}
4118-
return enumValues as any;
4118+
return enumValues;
41194119
}
41204120

41214121
get Values(): Values<T> {
41224122
const enumValues: any = {};
41234123
for (const val of this._def.values) {
41244124
enumValues[val] = val;
41254125
}
4126-
return enumValues as any;
4126+
return enumValues;
41274127
}
41284128

41294129
get Enum(): Values<T> {
41304130
const enumValues: any = {};
41314131
for (const val of this._def.values) {
41324132
enumValues[val] = val;
41334133
}
4134-
return enumValues as any;
4134+
return enumValues;
41354135
}
41364136

41374137
extract<ToExtract extends readonly [T[number], ...T[number][]]>(
@@ -4201,7 +4201,7 @@ export class ZodNativeEnum<T extends EnumLike> extends ZodType<T[keyof T], ZodNa
42014201
});
42024202
return INVALID;
42034203
}
4204-
return OK(input.data as any);
4204+
return OK(input.data);
42054205
}
42064206

42074207
get enum() {

packages/zod/src/v4/classic/tests/to-json-schema.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ describe("toJSONSchema", () => {
825825
z.toJSONSchema(a, {
826826
io: "input",
827827
override(ctx) {
828-
const def = (ctx.zodSchema as z.core.$ZodTypes)._zod.def;
828+
const def = ctx.zodSchema._zod.def;
829829
if (def.type === "object" && !def.catchall) {
830830
(ctx.jsonSchema as z.core.JSONSchema.ObjectSchema).additionalProperties = false;
831831
}

packages/zod/src/v4/core/checks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,9 @@ export const $ZodCheckNumberFormat: core.$constructor<$ZodCheckNumberFormat> = /
346346
if (input < minimum) {
347347
payload.issues.push({
348348
origin: "number",
349-
input: input as number,
349+
input,
350350
code: "too_small",
351-
minimum: minimum as number,
351+
minimum,
352352
inclusive: true,
353353
inst,
354354
continue: !def.abort,

packages/zod/src/v4/core/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export /*@__NO_SIDE_EFFECTS__*/ function $constructor<T extends ZodTrait, D = T[
2626
initializer(inst, def);
2727
// support prototype modifications
2828
for (const k in _.prototype) {
29-
if (!(k in inst)) Object.defineProperty(inst, k, { value: (_.prototype as any)[k].bind(inst) });
29+
if (!(k in inst)) Object.defineProperty(inst, k, { value: _.prototype[k].bind(inst) });
3030
}
3131
inst._zod.constr = _;
3232
inst._zod.def = def;

packages/zod/src/v4/core/schemas.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ export const $ZodBigInt: core.$constructor<$ZodBigInt> = /*@__PURE__*/ core.$con
11071107
inst._zod.parse = (payload, _ctx) => {
11081108
if (def.coerce)
11091109
try {
1110-
payload.value = BigInt(payload.value as any);
1110+
payload.value = BigInt(payload.value);
11111111
} catch (_) {}
11121112
const { value: input } = payload;
11131113
if (typeof input === "bigint") return payload;
@@ -2665,7 +2665,7 @@ export const $ZodEnum: core.$constructor<$ZodEnum> = /*@__PURE__*/ core.$constru
26652665

26662666
inst._zod.parse = (payload, _ctx) => {
26672667
const input = payload.value;
2668-
if (inst._zod.values.has(input as any)) {
2668+
if (inst._zod.values.has(input)) {
26692669
return payload;
26702670
}
26712671
payload.issues.push({
@@ -2717,7 +2717,7 @@ export const $ZodLiteral: core.$constructor<$ZodLiteral> = /*@__PURE__*/ core.$c
27172717

27182718
inst._zod.parse = (payload, _ctx) => {
27192719
const input = payload.value;
2720-
if (inst._zod.values.has(input as any)) {
2720+
if (inst._zod.values.has(input)) {
27212721
return payload;
27222722
}
27232723
payload.issues.push({

packages/zod/src/v4/core/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ export function normalizeParams<T>(_params: T): Normalize<T> {
461461
}
462462
delete params.message;
463463
if (typeof params.error === "string") return { ...params, error: () => params.error } as any;
464-
return params as any;
464+
return params;
465465
}
466466

467467
export function createTransparentProxy<T extends object>(getter: () => T): T {

0 commit comments

Comments
 (0)