@@ -187,8 +187,22 @@ namespace ts {
187187 const typeReferenceExtensions = [ ".d.ts" ] ;
188188
189189 function getEffectiveTypeRoots ( options : CompilerOptions , host : ModuleResolutionHost ) {
190- return options . typeRoots ||
191- map ( defaultTypeRoots , d => combinePaths ( options . configFilePath ? getDirectoryPath ( options . configFilePath ) : host . getCurrentDirectory ( ) , d ) ) ;
190+ if ( options . typeRoots ) {
191+ return options . typeRoots ;
192+ }
193+
194+ let currentDirectory : string ;
195+ if ( options . configFilePath ) {
196+ currentDirectory = getDirectoryPath ( options . configFilePath ) ;
197+ }
198+ else if ( host . getCurrentDirectory ) {
199+ currentDirectory = host . getCurrentDirectory ( ) ;
200+ }
201+
202+ if ( ! currentDirectory ) {
203+ return undefined ;
204+ }
205+ return map ( defaultTypeRoots , d => combinePaths ( currentDirectory , d ) ) ;
192206 }
193207
194208 /**
@@ -228,7 +242,7 @@ namespace ts {
228242 const failedLookupLocations : string [ ] = [ ] ;
229243
230244 // Check primary library paths
231- if ( typeRoots . length ) {
245+ if ( typeRoots && typeRoots . length ) {
232246 if ( traceEnabled ) {
233247 trace ( host , Diagnostics . Resolving_with_primary_search_path_0 , typeRoots . join ( ", " ) ) ;
234248 }
@@ -1046,9 +1060,11 @@ namespace ts {
10461060 let result : string [ ] = [ ] ;
10471061 if ( host . directoryExists && host . getDirectories ) {
10481062 const typeRoots = getEffectiveTypeRoots ( options , host ) ;
1049- for ( const root of typeRoots ) {
1050- if ( host . directoryExists ( root ) ) {
1051- result = result . concat ( host . getDirectories ( root ) ) ;
1063+ if ( typeRoots ) {
1064+ for ( const root of typeRoots ) {
1065+ if ( host . directoryExists ( root ) ) {
1066+ result = result . concat ( host . getDirectories ( root ) ) ;
1067+ }
10521068 }
10531069 }
10541070 }
0 commit comments