@@ -48,8 +48,8 @@ export const resolve = (
4848 ${ chalk . bold ( '<rootDir>' ) } is: ${ rootDir } ` ,
4949 ) ;
5050 }
51-
52- return module ;
51+ /// can cast as string since nulls will be thrown
52+ return module as string ;
5353} ;
5454
5555export const escapeGlobCharacters = ( path : Config . Path ) : Config . Glob =>
@@ -69,37 +69,50 @@ export const replaceRootDirInPath = (
6969 ) ;
7070} ;
7171
72- // TODO: Type as returning same type as input
73- const _replaceRootDirInObject = (
72+ const _replaceRootDirInObject = < T extends ReplaceRootDirConfigObj > (
7473 rootDir : Config . Path ,
75- config : any ,
76- ) : { [ key : string ] : unknown } => {
77- if ( config !== null ) {
78- const newConfig : { [ key : string ] : unknown } = { } ;
79- for ( const configKey in config ) {
80- newConfig [ configKey ] =
81- configKey === 'rootDir'
82- ? config [ configKey ]
83- : _replaceRootDirTags ( rootDir , config [ configKey ] ) ;
84- }
85- return newConfig ;
74+ config : T ,
75+ ) : T => {
76+ const newConfig = { } as T ;
77+ for ( const configKey in config ) {
78+ newConfig [ configKey ] =
79+ configKey === 'rootDir'
80+ ? config [ configKey ]
81+ : _replaceRootDirTags ( rootDir , config [ configKey ] ) ;
8682 }
87- return config ;
83+ return newConfig ;
8884} ;
8985
90- // TODO: Type as returning same type as input
91- export const _replaceRootDirTags = ( rootDir : Config . Path , config : any ) : any => {
86+ type OrArray < T > = T | Array < T > ;
87+ type ReplaceRootDirConfigObj = { [ key : string ] : Config . Path } ;
88+ type ReplaceRootDirConfigValues =
89+ | OrArray < ReplaceRootDirConfigObj >
90+ | OrArray < RegExp >
91+ | OrArray < Config . Path > ;
92+
93+ export const _replaceRootDirTags = < T extends ReplaceRootDirConfigValues > (
94+ rootDir : Config . Path ,
95+ config : T ,
96+ ) : T => {
97+ if ( config == null ) {
98+ return config ;
99+ }
92100 switch ( typeof config ) {
93101 case 'object' :
94102 if ( Array . isArray ( config ) ) {
95- return config . map ( item => _replaceRootDirTags ( rootDir , item ) ) ;
103+ /// can be string[] or {}[]
104+ return config . map ( item => _replaceRootDirTags ( rootDir , item ) ) as T ;
96105 }
97106 if ( config instanceof RegExp ) {
98107 return config ;
99108 }
100- return _replaceRootDirInObject ( rootDir , config ) ;
109+
110+ return _replaceRootDirInObject (
111+ rootDir ,
112+ config as ReplaceRootDirConfigObj ,
113+ ) as T ;
101114 case 'string' :
102- return replaceRootDirInPath ( rootDir , config ) ;
115+ return replaceRootDirInPath ( rootDir , config ) as T ;
103116 }
104117 return config ;
105118} ;
0 commit comments