Skip to content

Commit 64b3027

Browse files
committed
chore: use a while loop
1 parent d8732a2 commit 64b3027

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

packages/arg-parser/src/arg-parser.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,28 @@ import {
1717
} from './arg-metadata';
1818

1919
function unwrapType(type: unknown): z.ZodType {
20-
if (type instanceof z.ZodOptional || type instanceof z.ZodDefault) {
21-
return unwrapType(type.unwrap());
20+
assertZodType(type);
21+
let unwrappedType = z.clone(type);
22+
while (
23+
unwrappedType instanceof z.ZodOptional ||
24+
unwrappedType instanceof z.ZodDefault
25+
) {
26+
const nextWrap = unwrappedType.unwrap();
27+
assertZodType(nextWrap);
28+
unwrappedType = nextWrap;
2229
}
30+
31+
return type;
32+
}
33+
34+
function assertZodType(type: unknown): asserts type is z.ZodType {
2335
if (!(type instanceof z.ZodType)) {
2436
throw new Error(
2537
`Unknown schema field type: ${
2638
type && typeof type === 'object' ? type.constructor.name : typeof type
2739
}`
2840
);
2941
}
30-
return type;
3142
}
3243

3344
export const defaultParserOptions: Partial<YargsOptions> = {

0 commit comments

Comments
 (0)