mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:19:30 -06:00
Fix error messages and watch logic for new types default
- Updated getCannotFindNameDiagnosticForName to always suggest adding to types field - Fixed FileIncludeKind.AutomaticTypeDirectiveFile messages to always show "specified in compilerOptions" - Updated updateTypeRootsWatch to check for wildcard instead of just checking if types exists - Updated discoverTypings to discover when types is undefined or includes wildcard These changes ensure the new types default behavior is properly reflected in error messages and file watching. Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
This commit is contained in:
parent
387b02acf5
commit
5b122ff9cf
@ -27628,27 +27628,19 @@ 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 compilerOptions.types
|
||||
? 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
|
||||
: Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slashjquery;
|
||||
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;
|
||||
case "describe":
|
||||
case "suite":
|
||||
case "it":
|
||||
case "test":
|
||||
return compilerOptions.types
|
||||
? 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
|
||||
: 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;
|
||||
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;
|
||||
case "process":
|
||||
case "require":
|
||||
case "Buffer":
|
||||
case "module":
|
||||
return compilerOptions.types
|
||||
? 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
|
||||
: Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode;
|
||||
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;
|
||||
case "Bun":
|
||||
return compilerOptions.types
|
||||
? 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
|
||||
: Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_Bun_Try_npm_i_save_dev_types_Slashbun;
|
||||
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;
|
||||
case "Map":
|
||||
case "Set":
|
||||
case "Promise":
|
||||
|
||||
@ -400,7 +400,6 @@ export function createProgramDiagnostics(getCompilerOptionsObjectLiteralSyntax:
|
||||
) :
|
||||
undefined;
|
||||
case FileIncludeKind.AutomaticTypeDirectiveFile:
|
||||
if (!options.types) return undefined;
|
||||
configFileNode = getOptionsSyntaxByArrayElementValue(getCompilerOptionsObjectLiteralSyntax(), "types", reason.typeReference);
|
||||
message = Diagnostics.File_is_entry_point_of_type_library_specified_here;
|
||||
break;
|
||||
|
||||
@ -1667,7 +1667,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
|
||||
*/
|
||||
function updateTypeRootsWatch() {
|
||||
const options = resolutionHost.getCompilationSettings();
|
||||
if (options.types) {
|
||||
if (options.types && !options.types.includes("*")) {
|
||||
// No need to do any watch since resolution cache is going to handle the failed lookups
|
||||
// for the types added by this
|
||||
closeTypeRootsWatch();
|
||||
|
||||
@ -529,13 +529,9 @@ export function fileIncludeReasonToDiagnostics(program: Program, reason: FileInc
|
||||
options.outFile ? "--outFile" : "--out",
|
||||
);
|
||||
case FileIncludeKind.AutomaticTypeDirectiveFile: {
|
||||
const messageAndArgs: DiagnosticAndArguments = options.types ?
|
||||
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] :
|
||||
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];
|
||||
const messageAndArgs: DiagnosticAndArguments = 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];
|
||||
|
||||
return chainDiagnosticMessages(/*details*/ undefined, ...messageAndArgs);
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
if (!compilerOptions.types || compilerOptions.types.includes("*")) {
|
||||
const possibleSearchDirs = new Set(fileNames.map(getDirectoryPath));
|
||||
possibleSearchDirs.add(projectRootPath);
|
||||
possibleSearchDirs.forEach(searchDir => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user