diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 74bfdf3e961..9e9fb8e2ee2 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -341,8 +341,9 @@ namespace ts { type: "list", element: { name: "typeRoots", - type: "string" - } + type: "string", + isFilePath: true + } }, { name: "types", diff --git a/src/compiler/program.ts b/src/compiler/program.ts index f6cc048ace6..9cb000a4d61 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -217,9 +217,9 @@ namespace ts { // Check primary library paths if (typeRoots.length) { if (traceEnabled) { - trace(host, Diagnostics.Resolving_with_primary_search_path_0, typeRoots.join(', ')); + trace(host, Diagnostics.Resolving_with_primary_search_path_0, typeRoots.join(", ")); } - const primarySearchPaths = options.typeRoots || defaultTypeRoots; + const primarySearchPaths = typeRoots; for (const typeRoot of primarySearchPaths) { const candidate = combinePaths(typeRoot, typeReferenceDirectiveName); const candidateDirectory = getDirectoryPath(candidate); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index d9edd5a76c4..db34bb7c6e8 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2562,7 +2562,7 @@ namespace ts { target?: ScriptTarget; traceResolution?: boolean; types?: string[]; - // Paths used to used to compute primary types search locations + /** Paths used to used to compute primary types search locations */ typeRoots?: string[]; typesSearchPaths?: string[]; /*@internal*/ version?: boolean; diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 53b0c28671f..b887b5c7256 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -316,7 +316,7 @@ namespace ts.server { } getDirectories(path: string): string[] { - return this.host.getDirectories ? this.host.getDirectories(path) : []; + return this.host.getDirectories(path); } /** diff --git a/src/services/services.ts b/src/services/services.ts index 6d29310f93c..ba157afaf9f 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2141,7 +2141,7 @@ namespace ts { const getCanonicalFileName = createGetCanonicalFileName(!!useCaseSensitiveFileNames); function getKeyForCompilationSettings(settings: CompilerOptions): DocumentRegistryBucketKey { - return `_${settings.target}|${settings.module}|${settings.noResolve}|${settings.jsx}|${settings.allowJs}|${settings.baseUrl}|${settings.typeRoots}|${JSON.stringify(settings.rootDirs)}|${JSON.stringify(settings.paths)}`; + return `_${settings.target}|${settings.module}|${settings.noResolve}|${settings.jsx}|${settings.allowJs}|${settings.baseUrl}|${JSON.stringify(settings.typeRoots)}|${JSON.stringify(settings.rootDirs)}|${JSON.stringify(settings.paths)}`; } function getBucketForCompilationSettings(key: DocumentRegistryBucketKey, createIfMissing: boolean): FileMap { diff --git a/tests/baselines/reference/library-reference-6.symbols b/tests/baselines/reference/library-reference-6.symbols new file mode 100644 index 00000000000..595d43df3fa --- /dev/null +++ b/tests/baselines/reference/library-reference-6.symbols @@ -0,0 +1,16 @@ +=== /src/foo.ts === +/// +var x: string = alpha.a; +>x : Symbol(x, Decl(foo.ts, 1, 3)) +>alpha.a : Symbol(a, Decl(index.d.ts, 3, 20)) +>alpha : Symbol(alpha, Decl(index.d.ts, 3, 11)) +>a : Symbol(a, Decl(index.d.ts, 3, 20)) + +=== /node_modules/@types/alpha/index.d.ts === + +// The primary lookup folder is relative to tsconfig.json, if present + +declare var alpha: { a: string }; +>alpha : Symbol(alpha, Decl(index.d.ts, 3, 11)) +>a : Symbol(a, Decl(index.d.ts, 3, 20)) + diff --git a/tests/baselines/reference/library-reference-6.trace.json b/tests/baselines/reference/library-reference-6.trace.json index fc29f3f2478..21843c2ecf4 100644 --- a/tests/baselines/reference/library-reference-6.trace.json +++ b/tests/baselines/reference/library-reference-6.trace.json @@ -2,27 +2,11 @@ "======== Resolving type reference directive 'alpha', containing file '/src/foo.ts', root directory 'node_modules/@types'. ========", "Resolving with primary search path 'node_modules/@types'", "File 'node_modules/@types/alpha/package.json' does not exist.", - "File 'node_modules/@types/alpha/index.d.ts' does not exist.", - "Looking up in 'node_modules' folder, initial location '/src'", - "File '/src/node_modules/alpha.ts' does not exist.", - "File '/src/node_modules/alpha.d.ts' does not exist.", - "File '/src/node_modules/alpha/package.json' does not exist.", - "File '/src/node_modules/alpha/index.ts' does not exist.", - "File '/src/node_modules/alpha/index.d.ts' does not exist.", - "File '/src/node_modules/@types/alpha.ts' does not exist.", - "File '/src/node_modules/@types/alpha.d.ts' does not exist.", - "File '/src/node_modules/@types/alpha/package.json' does not exist.", - "File '/src/node_modules/@types/alpha/index.ts' does not exist.", - "File '/src/node_modules/@types/alpha/index.d.ts' does not exist.", - "File '/node_modules/alpha.ts' does not exist.", - "File '/node_modules/alpha.d.ts' does not exist.", - "File '/node_modules/alpha/package.json' does not exist.", - "File '/node_modules/alpha/index.ts' does not exist.", - "File '/node_modules/alpha/index.d.ts' does not exist.", - "File '/node_modules/@types/alpha.ts' does not exist.", - "File '/node_modules/@types/alpha.d.ts' does not exist.", - "File '/node_modules/@types/alpha/package.json' does not exist.", - "File '/node_modules/@types/alpha/index.ts' does not exist.", - "File '/node_modules/@types/alpha/index.d.ts' does not exist.", - "======== Type reference directive 'alpha' was not resolved. ========" + "File 'node_modules/@types/alpha/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'alpha' was successfully resolved to 'node_modules/@types/alpha/index.d.ts', primary: true. ========", + "======== Resolving type reference directive 'alpha', containing file '/src/__inferred type names__.ts', root directory 'node_modules/@types'. ========", + "Resolving with primary search path 'node_modules/@types'", + "File 'node_modules/@types/alpha/package.json' does not exist.", + "File 'node_modules/@types/alpha/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'alpha' was successfully resolved to 'node_modules/@types/alpha/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-6.types b/tests/baselines/reference/library-reference-6.types new file mode 100644 index 00000000000..e2762c0943a --- /dev/null +++ b/tests/baselines/reference/library-reference-6.types @@ -0,0 +1,16 @@ +=== /src/foo.ts === +/// +var x: string = alpha.a; +>x : string +>alpha.a : string +>alpha : { a: string; } +>a : string + +=== /node_modules/@types/alpha/index.d.ts === + +// The primary lookup folder is relative to tsconfig.json, if present + +declare var alpha: { a: string }; +>alpha : { a: string; } +>a : string + diff --git a/tests/baselines/reference/moduleResolutionWithExtensions.trace.json b/tests/baselines/reference/moduleResolutionWithExtensions.trace.json index 6e6589d7c1f..7dc9e8c104b 100644 --- a/tests/baselines/reference/moduleResolutionWithExtensions.trace.json +++ b/tests/baselines/reference/moduleResolutionWithExtensions.trace.json @@ -3,11 +3,13 @@ "Module resolution kind is not specified, using 'NodeJs'.", "Loading module as file / folder, candidate module location '/src/a'.", "File '/src/a.ts' exist - use it as a name resolution result.", + "Resolving real path for '/src/a.ts', result '/src/a.ts'", "======== Module name './a' was successfully resolved to '/src/a.ts'. ========", "======== Resolving module './a.ts' from '/src/c.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module as file / folder, candidate module location '/src/a.ts'.", "File '/src/a.ts' exist - use it as a name resolution result.", + "Resolving real path for '/src/a.ts', result '/src/a.ts'", "======== Module name './a.ts' was successfully resolved to '/src/a.ts'. ========", "======== Resolving module './a.js' from '/src/d.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -17,6 +19,7 @@ "File '/src/a.js.d.ts' does not exist.", "File name '/src/a.js' has a '.js' extension - stripping it", "File '/src/a.ts' exist - use it as a name resolution result.", + "Resolving real path for '/src/a.ts', result '/src/a.ts'", "======== Module name './a.js' was successfully resolved to '/src/a.ts'. ========", "======== Resolving module './jquery.js' from '/src/jquery_user_1.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -28,5 +31,6 @@ "File '/src/jquery.ts' does not exist.", "File '/src/jquery.tsx' does not exist.", "File '/src/jquery.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/src/jquery.d.ts', result '/src/jquery.d.ts'", "======== Module name './jquery.js' was successfully resolved to '/src/jquery.d.ts'. ========" ] \ No newline at end of file