@@ -45,6 +45,10 @@ function isUserDefinedProperty(descriptor: PropertyDescriptor): boolean {
4545 return descriptor . writable === true && descriptor . enumerable === true ;
4646}
4747
48+ interface CollectionOptions {
49+ strict ?: boolean ;
50+ }
51+
4852/**
4953 * Collects argument definitions from an instance.
5054 *
@@ -53,10 +57,12 @@ function isUserDefinedProperty(descriptor: PropertyDescriptor): boolean {
5357 * duplicate short flags.
5458 *
5559 * @param instance - The class instance to analyze
60+ * @param options - Configuration options for metadata collection
5661 * @returns Object containing parsed options and positional argument definitions
5762 */
5863export function collectInstanceArgumentDefs (
5964 instance : Record < string , unknown > ,
65+ options : CollectionOptions = { strict : true } ,
6066) : {
6167 parsedArgs : ParsedArg [ ] ;
6268 argumentDefs : ArgumentDef [ ] ;
@@ -98,11 +104,16 @@ export function collectInstanceArgumentDefs(
98104 if ( propertyMetadata ?. argument ) {
99105 // Positional argument
100106 if ( instance [ propName ] === undefined && ! propertyMetadata . type ) {
101- throw new Error (
102- `Property '${ propName } ' has no default value and no @type() decorator. ` +
103- `Use @type("string"), @type("number"), etc. to specify the expected type. ` +
104- `This is required because TypeScript cannot infer the type from undefined values.` ,
105- ) ;
107+ if ( options . strict ) {
108+ throw new Error (
109+ `Property '${ propName } ' has no default value and no @type() decorator. ` +
110+ `Use @type("string"), @type("number"), etc. to specify the expected type. ` +
111+ `This is required because TypeScript cannot infer the type from undefined values.` ,
112+ ) ;
113+ } else {
114+ // In non-strict mode, skip properties with undetermined types
115+ continue ;
116+ }
106117 }
107118
108119 argumentDefs . push ( {
@@ -116,11 +127,16 @@ export function collectInstanceArgumentDefs(
116127 } else if ( propertyMetadata ?. rawRest ) {
117128 // Raw rest argument
118129 if ( instance [ propName ] === undefined && ! propertyMetadata . type ) {
119- throw new Error (
120- `Property '${ propName } ' has no default value and no @type() decorator. ` +
121- `Use @type("string[]") or another array type to specify the expected type. ` +
122- `This is required because TypeScript cannot infer the type from undefined values.` ,
123- ) ;
130+ if ( options . strict ) {
131+ throw new Error (
132+ `Property '${ propName } ' has no default value and no @type() decorator. ` +
133+ `Use @type("string[]") or another array type to specify the expected type. ` +
134+ `This is required because TypeScript cannot infer the type from undefined values.` ,
135+ ) ;
136+ } else {
137+ // In non-strict mode, skip properties with undetermined types
138+ continue ;
139+ }
124140 }
125141
126142 argumentDefs . push ( {
@@ -134,11 +150,16 @@ export function collectInstanceArgumentDefs(
134150 } else {
135151 // Regular option
136152 if ( instance [ propName ] === undefined && ! propertyMetadata ?. type ) {
137- throw new Error (
138- `Property '${ propName } ' has no default value and no @type() decorator. ` +
139- `Use @type("string"), @type("number"), etc. to specify the expected type. ` +
140- `This is required because TypeScript cannot infer the type from undefined values.` ,
141- ) ;
153+ if ( options . strict ) {
154+ throw new Error (
155+ `Property '${ propName } ' has no default value and no @type() decorator. ` +
156+ `Use @type("string"), @type("number"), etc. to specify the expected type. ` +
157+ `This is required because TypeScript cannot infer the type from undefined values.` ,
158+ ) ;
159+ } else {
160+ // In non-strict mode, skip properties with undetermined types
161+ continue ;
162+ }
142163 }
143164
144165 parsedArgs . push ( {
0 commit comments