@@ -16,12 +16,16 @@ import {
1616 UnsupportedCliArgumentError ,
1717} from './arg-metadata' ;
1818
19- function unwrapType ( type : unknown ) : unknown {
20- if ( type instanceof z . ZodOptional ) {
19+ function unwrapType ( type : unknown ) : z . ZodType {
20+ if ( type instanceof z . ZodOptional || type instanceof z . ZodDefault ) {
2121 return unwrapType ( type . unwrap ( ) ) ;
2222 }
23- if ( type instanceof z . ZodDefault ) {
24- return unwrapType ( type . unwrap ( ) ) ;
23+ if ( ! ( type instanceof z . ZodType ) ) {
24+ throw new Error (
25+ `Unknown schema field type: ${
26+ type && typeof type === 'object' ? type . constructor . name : typeof type
27+ } `
28+ ) ;
2529 }
2630 return type ;
2731}
@@ -49,20 +53,20 @@ export function generateYargsOptionsFromSchema({
4953 schema : z . ZodObject ;
5054 parserOptions ?: Partial < YargsOptions > ;
5155} ) : YargsOptions {
52- const options = {
53- ...parserOptions ,
54- string : < string [ ] > [ ] ,
55- boolean : < string [ ] > [ ] ,
56- array : < string [ ] > [ ] ,
57- alias : < Record < string , string > > { } ,
58- coerce : < Record < string , ( value : unknown ) => unknown > > { } ,
59- number : < string [ ] > [ ] ,
60- } satisfies Required <
56+ const options : Required <
6157 Pick <
6258 YargsOptions ,
6359 'string' | 'boolean' | 'array' | 'alias' | 'coerce' | 'number'
64- >
65- > ;
60+ > & { array : string [ ] }
61+ > = {
62+ ...parserOptions ,
63+ string : [ ] ,
64+ boolean : [ ] ,
65+ array : [ ] ,
66+ alias : { } ,
67+ coerce : { } ,
68+ number : [ ] ,
69+ } ;
6670
6771 for ( const [ fieldName , fieldSchema ] of Object . entries ( schema . shape ) ) {
6872 const meta = getArgumentMetadata ( schema , fieldName ) ;
0 commit comments