@@ -179,10 +179,12 @@ const getArguments = (schema = webpackSchema) => {
179179 values : schemaPart . enum
180180 } ;
181181 }
182- if ( schemaPart . const !== undefined ) {
182+ // JSONSchema4 has no `const`, so it reads through the index signature.
183+ const constValue = /** @type {EnumValue | undefined } */ ( schemaPart . const ) ;
184+ if ( constValue !== undefined ) {
183185 return {
184186 type : "enum" ,
185- values : [ schemaPart . const ]
187+ values : [ constValue ]
186188 } ;
187189 }
188190 switch ( schemaPart . type ) {
@@ -509,6 +511,8 @@ const getArguments = (schema = webpackSchema) => {
509511
510512/** @typedef {ObjectConfiguration | ParsedValue | undefined } ConfigurationValue */
511513
514+ /** @typedef {ObjectConfiguration | ConfigurationValue[] | Value | null | undefined } PathValue */
515+
512516/** @type {WeakMap<ConfigurationValue[], number> } */
513517const cliAddedItems = new WeakMap ( ) ;
514518
@@ -527,7 +531,7 @@ const isUnsafeKey = (name) =>
527531 * @param {ObjectConfiguration } config configuration
528532 * @param {string } schemaPath path in the config
529533 * @param {number | undefined } index index of value when multiple values are provided, otherwise undefined
530- * @returns {{ problem?: LocalProblem, object?: ObjectConfiguration, property?: Property, value?: ConfigurationValue } } problem or object with property and value
534+ * @returns {{ problem?: LocalProblem, object?: ObjectConfiguration | ConfigurationValue[] , property?: Property, value?: ConfigurationValue } } problem or object with property and value
531535 */
532536const getObjectAndProperty = ( config , schemaPath , index = 0 ) => {
533537 if ( ! schemaPath ) return { value : config } ;
@@ -546,6 +550,7 @@ const getObjectAndProperty = (config, schemaPath, index = 0) => {
546550 }
547551 } ;
548552 }
553+ /** @type {PathValue } */
549554 let value = current [ name ] ;
550555 if ( isArray ) {
551556 if ( value === undefined ) {
@@ -577,7 +582,7 @@ const getObjectAndProperty = (config, schemaPath, index = 0) => {
577582 }
578583 } ;
579584 }
580- value = value [ x ] ;
585+ value = /** @type { ObjectConfiguration } */ ( value [ x ] ) ;
581586 }
582587 } else if ( value === undefined ) {
583588 value = current [ name ] = { } ;
@@ -589,7 +594,7 @@ const getObjectAndProperty = (config, schemaPath, index = 0) => {
589594 }
590595 } ;
591596 }
592- current = value ;
597+ current = /** @type { ObjectConfiguration } */ ( value ) ;
593598 i ++ ;
594599 }
595600 if ( isUnsafeKey ( property . endsWith ( "[]" ) ? property . slice ( 0 , - 2 ) : property ) ) {
@@ -600,18 +605,28 @@ const getObjectAndProperty = (config, schemaPath, index = 0) => {
600605 }
601606 } ;
602607 }
608+ /** @type {ConfigurationValue } */
603609 const value = current [ property ] ;
604610 if ( property . endsWith ( "[]" ) ) {
605611 const name = property . slice ( 0 , - 2 ) ;
612+ /** @type {PathValue } */
606613 const value = current [ name ] ;
607614 if ( value === undefined ) {
608- current [ name ] = [ ...Array . from ( { length : index } ) , undefined ] ;
609- cliAddedItems . set ( current [ name ] , index + 1 ) ;
610- return { object : current [ name ] , property : index , value : undefined } ;
615+ /** @type {ConfigurationValue[] } */
616+ const array = [ ...Array . from ( { length : index } ) , undefined ] ;
617+ current [ name ] = array ;
618+ cliAddedItems . set ( array , index + 1 ) ;
619+ return { object : array , property : index , value : undefined } ;
611620 } else if ( ! Array . isArray ( value ) ) {
612- current [ name ] = [ value , ...Array . from ( { length : index } ) , undefined ] ;
613- cliAddedItems . set ( current [ name ] , index + 1 ) ;
614- return { object : current [ name ] , property : index + 1 , value : undefined } ;
621+ /** @type {ConfigurationValue[] } */
622+ const array = [
623+ /** @type {ConfigurationValue } */ ( value ) ,
624+ ...Array . from ( { length : index } ) ,
625+ undefined
626+ ] ;
627+ current [ name ] = array ;
628+ cliAddedItems . set ( array , index + 1 ) ;
629+ return { object : array , property : index + 1 , value : undefined } ;
615630 }
616631 let addedItems = cliAddedItems . get ( value ) || 0 ;
617632 while ( addedItems <= index ) {
0 commit comments