From 7f169c18f22fdbcff395bb01495ab248a3dcce32 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 Jan 2026 19:04:03 +0000 Subject: [PATCH] Fix compiler logic to check for wildcard correctly - checker.ts: Check for wildcard before choosing error message - programDiagnostics.ts: Check for wildcard before returning early - watch.ts: Check for wildcard to choose correct message - jsTyping.ts: Use optional chaining for wildcard check - tscWatch tests: Use wildcard for tests that dynamically install types These functions should only show "add to types" messages when wildcard is NOT present. Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com> --- src/compiler/checker.ts | 16 ++++++++++++---- src/compiler/programDiagnostics.ts | 1 + src/compiler/watch.ts | 6 +++++- src/jsTyping/jsTyping.ts | 2 +- .../unittests/tscWatch/resolutionCache.ts | 4 ++-- .../unittests/tsserver/resolutionCache.ts | 2 +- 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 60c4b5d1d4e..92898f8b4f8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -27628,19 +27628,27 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { case "console": return Diagnostics.Cannot_find_name_0_Do_you_need_to_change_your_target_library_Try_changing_the_lib_compiler_option_to_include_dom; case "$": - return Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slashjquery_and_then_add_jquery_to_the_types_field_in_your_tsconfig; + return compilerOptions.types?.includes("*") + ? Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slashjquery + : Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slashjquery_and_then_add_jquery_to_the_types_field_in_your_tsconfig; case "describe": case "suite": case "it": case "test": - return Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_types_Slashjest_or_npm_i_save_dev_types_Slashmocha_and_then_add_jest_or_mocha_to_the_types_field_in_your_tsconfig; + return compilerOptions.types?.includes("*") + ? Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_types_Slashjest_or_npm_i_save_dev_types_Slashmocha + : Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_types_Slashjest_or_npm_i_save_dev_types_Slashmocha_and_then_add_jest_or_mocha_to_the_types_field_in_your_tsconfig; case "process": case "require": case "Buffer": case "module": - return Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode_and_then_add_node_to_the_types_field_in_your_tsconfig; + return compilerOptions.types?.includes("*") + ? Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode + : Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode_and_then_add_node_to_the_types_field_in_your_tsconfig; case "Bun": - return Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_Bun_Try_npm_i_save_dev_types_Slashbun_and_then_add_bun_to_the_types_field_in_your_tsconfig; + return compilerOptions.types?.includes("*") + ? Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_Bun_Try_npm_i_save_dev_types_Slashbun + : Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_Bun_Try_npm_i_save_dev_types_Slashbun_and_then_add_bun_to_the_types_field_in_your_tsconfig; case "Map": case "Set": case "Promise": diff --git a/src/compiler/programDiagnostics.ts b/src/compiler/programDiagnostics.ts index 45adc9ca756..ead43fb745d 100644 --- a/src/compiler/programDiagnostics.ts +++ b/src/compiler/programDiagnostics.ts @@ -400,6 +400,7 @@ export function createProgramDiagnostics(getCompilerOptionsObjectLiteralSyntax: ) : undefined; case FileIncludeKind.AutomaticTypeDirectiveFile: + if (options.types?.includes("*")) return undefined; configFileNode = getOptionsSyntaxByArrayElementValue(getCompilerOptionsObjectLiteralSyntax(), "types", reason.typeReference); message = Diagnostics.File_is_entry_point_of_type_library_specified_here; break; diff --git a/src/compiler/watch.ts b/src/compiler/watch.ts index 19ba279f011..ee5905a336a 100644 --- a/src/compiler/watch.ts +++ b/src/compiler/watch.ts @@ -529,7 +529,11 @@ export function fileIncludeReasonToDiagnostics(program: Program, reason: FileInc options.outFile ? "--outFile" : "--out", ); case FileIncludeKind.AutomaticTypeDirectiveFile: { - const messageAndArgs: DiagnosticAndArguments = reason.packageId ? + const messageAndArgs: DiagnosticAndArguments = options.types?.includes("*") ? + reason.packageId ? + [Diagnostics.Entry_point_for_implicit_type_library_0_with_packageId_1, reason.typeReference, packageIdToString(reason.packageId)] : + [Diagnostics.Entry_point_for_implicit_type_library_0, reason.typeReference] : + reason.packageId ? [Diagnostics.Entry_point_of_type_library_0_specified_in_compilerOptions_with_packageId_1, reason.typeReference, packageIdToString(reason.packageId)] : [Diagnostics.Entry_point_of_type_library_0_specified_in_compilerOptions, reason.typeReference]; diff --git a/src/jsTyping/jsTyping.ts b/src/jsTyping/jsTyping.ts index 3153d329d10..472ef3dfd0d 100644 --- a/src/jsTyping/jsTyping.ts +++ b/src/jsTyping/jsTyping.ts @@ -133,7 +133,7 @@ export function discoverTypings( const exclude = typeAcquisition.exclude || []; // Directories to search for package.json, bower.json and other typing information - if (!compilerOptions.types || compilerOptions.types.includes("*")) { + if (!compilerOptions.types || compilerOptions.types?.includes("*")) { const possibleSearchDirs = new Set(fileNames.map(getDirectoryPath)); possibleSearchDirs.add(projectRootPath); possibleSearchDirs.forEach(searchDir => { diff --git a/src/testRunner/unittests/tscWatch/resolutionCache.ts b/src/testRunner/unittests/tscWatch/resolutionCache.ts index b3e8c36d8b3..bc739556d68 100644 --- a/src/testRunner/unittests/tscWatch/resolutionCache.ts +++ b/src/testRunner/unittests/tscWatch/resolutionCache.ts @@ -243,7 +243,7 @@ describe("unittests:: tscWatch:: resolutionCache:: tsc-watch module resolution c content: `import * as fs from "fs";`, }, { path: "/users/username/projects/project/tsconfig.json", - content: jsonToReadableText({ compilerOptions: { types: ["node"] } }), + content: jsonToReadableText({ compilerOptions: { types: ["*"] } }), }], { currentDirectory: "/users/username/projects/project" }), edits: [ { @@ -568,7 +568,7 @@ declare namespace NodeJS { }; const tsconfig: File = { path: `/user/username/projects/myproject/tsconfig.json`, - content: jsonToReadableText({ compilerOptions: { types: ["node"] } }), + content: jsonToReadableText({ compilerOptions: { types: ["*"] } }), }; const { nodeAtTypesIndex, nodeAtTypesBase, nodeAtTypes36Base, nodeAtTypesGlobals } = getNodeAtTypes(); return TestServerHost.createWatchedSystem( diff --git a/src/testRunner/unittests/tsserver/resolutionCache.ts b/src/testRunner/unittests/tsserver/resolutionCache.ts index bb09c13027c..01bd8182c7e 100644 --- a/src/testRunner/unittests/tsserver/resolutionCache.ts +++ b/src/testRunner/unittests/tsserver/resolutionCache.ts @@ -59,7 +59,7 @@ describe("unittests:: tsserver:: resolutionCache:: tsserverProjectSystem watchin const tsconfig = { path: "/users/username/projects/project/tsconfig.json", content: jsonToReadableText({ - compilerOptions: { types: ["lib1", "lib2"] }, + compilerOptions: { types: ["*"] }, exclude: ["node_modules"], }), };