mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 03:09:39 -06:00
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>
This commit is contained in:
parent
361221e4d2
commit
7f169c18f2
@ -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":
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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];
|
||||
|
||||
|
||||
@ -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 => {
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -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"],
|
||||
}),
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user