@@ -616,10 +616,10 @@ namespace ts {
616616 }
617617 }
618618 else if ( id === "include" ) {
619- options . include = isArray ( jsonTypingOptions [ id ] ) ? < string [ ] > jsonTypingOptions [ id ] : [ ] ;
619+ options . include = ConvertJsonOptionToStringArray ( id , jsonTypingOptions [ id ] , errors ) ;
620620 }
621621 else if ( id === "exclude" ) {
622- options . exclude = isArray ( jsonTypingOptions [ id ] ) ? < string [ ] > jsonTypingOptions [ id ] : [ ] ;
622+ options . exclude = ConvertJsonOptionToStringArray ( id , jsonTypingOptions [ id ] , errors ) ;
623623 }
624624 else {
625625 errors . push ( createCompilerDiagnostic ( Diagnostics . Unknown_typing_option_0 , id ) ) ;
@@ -668,28 +668,7 @@ namespace ts {
668668 break ;
669669 case "object" :
670670 // "object" options with 'isFilePath' = true expected to be string arrays
671- let paths : string [ ] = [ ] ;
672- let invalidOptionType = false ;
673- if ( ! isArray ( value ) ) {
674- invalidOptionType = true ;
675- }
676- else {
677- for ( const element of < any [ ] > value ) {
678- if ( typeof element === "string" ) {
679- paths . push ( normalizePath ( combinePaths ( basePath , element ) ) ) ;
680- }
681- else {
682- invalidOptionType = true ;
683- break ;
684- }
685- }
686- }
687- if ( invalidOptionType ) {
688- errors . push ( createCompilerDiagnostic ( Diagnostics . Option_0_should_have_array_of_strings_as_a_value , opt . name ) ) ;
689- }
690- else {
691- value = paths ;
692- }
671+ value = ConvertJsonOptionToStringArray ( opt . name , value , errors , ( element ) => normalizePath ( combinePaths ( basePath , element ) ) ) ;
693672 break ;
694673 }
695674 if ( value === "" ) {
@@ -709,4 +688,28 @@ namespace ts {
709688
710689 return { options, errors } ;
711690 }
691+
692+ function ConvertJsonOptionToStringArray ( optionName : string , optionJson : any , errors : Diagnostic [ ] , func ?: ( element : string ) => string ) : string [ ] {
693+ let items : string [ ] = [ ] ;
694+ let invalidOptionType = false ;
695+ if ( ! isArray ( optionJson ) ) {
696+ invalidOptionType = true ;
697+ }
698+ else {
699+ for ( const element of < any [ ] > optionJson ) {
700+ if ( typeof element === "string" ) {
701+ const item = func ? func ( element ) : element ;
702+ items . push ( item ) ;
703+ }
704+ else {
705+ invalidOptionType = true ;
706+ break ;
707+ }
708+ }
709+ }
710+ if ( invalidOptionType ) {
711+ errors . push ( createCompilerDiagnostic ( Diagnostics . Option_0_should_have_array_of_strings_as_a_value , optionName ) ) ;
712+ }
713+ return items ;
714+ }
712715}
0 commit comments