Skip to content

Commit 7f169c1

Browse files
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>
1 parent 361221e commit 7f169c1

File tree

6 files changed

+22
-9
lines changed

6 files changed

+22
-9
lines changed

src/compiler/checker.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27628,19 +27628,27 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2762827628
case "console":
2762927629
return Diagnostics.Cannot_find_name_0_Do_you_need_to_change_your_target_library_Try_changing_the_lib_compiler_option_to_include_dom;
2763027630
case "$":
27631-
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;
27631+
return compilerOptions.types?.includes("*")
27632+
? Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slashjquery
27633+
: 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;
2763227634
case "describe":
2763327635
case "suite":
2763427636
case "it":
2763527637
case "test":
27636-
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;
27638+
return compilerOptions.types?.includes("*")
27639+
? 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
27640+
: 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;
2763727641
case "process":
2763827642
case "require":
2763927643
case "Buffer":
2764027644
case "module":
27641-
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;
27645+
return compilerOptions.types?.includes("*")
27646+
? Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode
27647+
: 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;
2764227648
case "Bun":
27643-
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;
27649+
return compilerOptions.types?.includes("*")
27650+
? Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_Bun_Try_npm_i_save_dev_types_Slashbun
27651+
: 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;
2764427652
case "Map":
2764527653
case "Set":
2764627654
case "Promise":

src/compiler/programDiagnostics.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ export function createProgramDiagnostics(getCompilerOptionsObjectLiteralSyntax:
400400
) :
401401
undefined;
402402
case FileIncludeKind.AutomaticTypeDirectiveFile:
403+
if (options.types?.includes("*")) return undefined;
403404
configFileNode = getOptionsSyntaxByArrayElementValue(getCompilerOptionsObjectLiteralSyntax(), "types", reason.typeReference);
404405
message = Diagnostics.File_is_entry_point_of_type_library_specified_here;
405406
break;

src/compiler/watch.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,11 @@ export function fileIncludeReasonToDiagnostics(program: Program, reason: FileInc
529529
options.outFile ? "--outFile" : "--out",
530530
);
531531
case FileIncludeKind.AutomaticTypeDirectiveFile: {
532-
const messageAndArgs: DiagnosticAndArguments = reason.packageId ?
532+
const messageAndArgs: DiagnosticAndArguments = options.types?.includes("*") ?
533+
reason.packageId ?
534+
[Diagnostics.Entry_point_for_implicit_type_library_0_with_packageId_1, reason.typeReference, packageIdToString(reason.packageId)] :
535+
[Diagnostics.Entry_point_for_implicit_type_library_0, reason.typeReference] :
536+
reason.packageId ?
533537
[Diagnostics.Entry_point_of_type_library_0_specified_in_compilerOptions_with_packageId_1, reason.typeReference, packageIdToString(reason.packageId)] :
534538
[Diagnostics.Entry_point_of_type_library_0_specified_in_compilerOptions, reason.typeReference];
535539

src/jsTyping/jsTyping.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export function discoverTypings(
133133
const exclude = typeAcquisition.exclude || [];
134134

135135
// Directories to search for package.json, bower.json and other typing information
136-
if (!compilerOptions.types || compilerOptions.types.includes("*")) {
136+
if (!compilerOptions.types || compilerOptions.types?.includes("*")) {
137137
const possibleSearchDirs = new Set(fileNames.map(getDirectoryPath));
138138
possibleSearchDirs.add(projectRootPath);
139139
possibleSearchDirs.forEach(searchDir => {

src/testRunner/unittests/tscWatch/resolutionCache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ describe("unittests:: tscWatch:: resolutionCache:: tsc-watch module resolution c
243243
content: `import * as fs from "fs";`,
244244
}, {
245245
path: "/users/username/projects/project/tsconfig.json",
246-
content: jsonToReadableText({ compilerOptions: { types: ["node"] } }),
246+
content: jsonToReadableText({ compilerOptions: { types: ["*"] } }),
247247
}], { currentDirectory: "/users/username/projects/project" }),
248248
edits: [
249249
{
@@ -568,7 +568,7 @@ declare namespace NodeJS {
568568
};
569569
const tsconfig: File = {
570570
path: `/user/username/projects/myproject/tsconfig.json`,
571-
content: jsonToReadableText({ compilerOptions: { types: ["node"] } }),
571+
content: jsonToReadableText({ compilerOptions: { types: ["*"] } }),
572572
};
573573
const { nodeAtTypesIndex, nodeAtTypesBase, nodeAtTypes36Base, nodeAtTypesGlobals } = getNodeAtTypes();
574574
return TestServerHost.createWatchedSystem(

src/testRunner/unittests/tsserver/resolutionCache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe("unittests:: tsserver:: resolutionCache:: tsserverProjectSystem watchin
5959
const tsconfig = {
6060
path: "/users/username/projects/project/tsconfig.json",
6161
content: jsonToReadableText({
62-
compilerOptions: { types: ["lib1", "lib2"] },
62+
compilerOptions: { types: ["*"] },
6363
exclude: ["node_modules"],
6464
}),
6565
};

0 commit comments

Comments
 (0)