Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7c95cfb
Add utility function; update sites that depend on old wildcard behavior
RyanCavanaugh Jan 27, 2026
b18e524
Make the code change in core utils
RyanCavanaugh Jan 27, 2026
03a711e
Add baselines that just change error message
RyanCavanaugh Jan 27, 2026
0c104b8
Trace-only changes, hopefully
RyanCavanaugh Jan 28, 2026
9ec13ae
Update testcases
RyanCavanaugh Jan 28, 2026
c1d487f
More traces
RyanCavanaugh Jan 28, 2026
d0db3cc
Format
RyanCavanaugh Jan 28, 2026
5186331
One more test
RyanCavanaugh Jan 28, 2026
499cd4c
Update .d.ts
RyanCavanaugh Jan 28, 2026
2312bd9
Update typingsInstaller tests
RyanCavanaugh Jan 28, 2026
787f9b6
Fix misc unit tests
RyanCavanaugh Jan 29, 2026
868fb7c
Add types: * to auto-import unit test
RyanCavanaugh Jan 29, 2026
423e1c4
Use wildcard types for inferred JS project unless otherwise directed
RyanCavanaugh Jan 29, 2026
00c6b56
Correctly handle lack of needed wildcard watch on types
RyanCavanaugh Jan 29, 2026
7659973
Corrected test corrections
RyanCavanaugh Jan 29, 2026
1795860
Fix test with incorrect tsconfig
RyanCavanaugh Jan 30, 2026
9f5dbbd
Correctly attribute wildcard types
RyanCavanaugh Jan 30, 2026
e5d646b
Recommend installing types/node for missing modules
RyanCavanaugh Jan 30, 2026
7382bbb
lint
RyanCavanaugh Jan 30, 2026
27b74d6
Offer installing @types/node when can't resolve nodejs modules
RyanCavanaugh Jan 30, 2026
49086b2
Update src/compiler/programDiagnostics.ts
RyanCavanaugh Jan 30, 2026
8a9515d
Follow-up to Sheetal's edit
RyanCavanaugh Jan 30, 2026
ec8e039
Add timeout run so we can see zero errors in this test
RyanCavanaugh Jan 30, 2026
dd8df7a
Same for this test
RyanCavanaugh Jan 30, 2026
25b88ea
Merge remote-tracking branch 'upstream/main' into fix62195_2
RyanCavanaugh Jan 30, 2026
d398d5b
Merge conflicted fourslash tests
RyanCavanaugh Jan 30, 2026
c374421
typo
RyanCavanaugh Jan 30, 2026
5dc64a2
Format
RyanCavanaugh Jan 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
46 changes: 32 additions & 14 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,7 @@ import {
NodeBuilderFlags,
nodeCanBeDecorated,
NodeCheckFlags,
nodeCoreModules,
NodeFlags,
nodeHasName,
nodeIsMissing,
Expand Down Expand Up @@ -1121,6 +1122,7 @@ import {
UnionType,
UnionTypeNode,
UniqueESSymbolType,
usesWildcardTypes,
usingSingleLineStringWriter,
VariableDeclaration,
VariableDeclarationList,
Expand Down Expand Up @@ -4708,9 +4710,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {

function resolveExternalModuleName(location: Node, moduleReferenceExpression: Expression, ignoreErrors?: boolean, errorMessage?: DiagnosticMessage): Symbol | undefined {
const isClassic = getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.Classic;
errorMessage ??= isClassic ?
errorMessage ??= getCannotResolveModuleNameErrorForSpecificModule(moduleReferenceExpression) ?? (isClassic ?
Diagnostics.Cannot_find_module_0_Did_you_mean_to_set_the_moduleResolution_option_to_nodenext_or_to_add_aliases_to_the_paths_option
: Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations;
: Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations);
return resolveExternalModuleNameWorker(location, moduleReferenceExpression, ignoreErrors ? undefined : errorMessage, ignoreErrors);
}

Expand Down Expand Up @@ -27643,27 +27645,29 @@ 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 usesWildcardTypes(compilerOptions)
? 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 "beforeEach":
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 usesWildcardTypes(compilerOptions)
? 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 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;
case "NodeJS":
return usesWildcardTypes(compilerOptions)
? 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 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 usesWildcardTypes(compilerOptions)
? 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":
Expand Down Expand Up @@ -27698,6 +27702,20 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
}

function getCannotResolveModuleNameErrorForSpecificModule(moduleName: Expression): DiagnosticMessage | undefined {
if (moduleName.kind === SyntaxKind.StringLiteral) {
if (nodeCoreModules.has((moduleName as StringLiteral).text)) {
if (usesWildcardTypes(compilerOptions)) {
return Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode;
}
else {
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 undefined;
}

function getResolvedSymbol(node: Identifier): Symbol {
const links = getNodeLinks(node);
if (!links.resolvedSymbol) {
Expand Down
19 changes: 12 additions & 7 deletions src/compiler/moduleNameResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ import {
emptyArray,
endsWith,
ensureTrailingDirectorySeparator,
equateValues,
every,
Extension,
extensionIsTS,
fileExtensionIs,
fileExtensionIsOneOf,
filter,
firstDefined,
flatten,
forEach,
forEachAncestorDirectory,
formatMessage,
Expand Down Expand Up @@ -105,6 +107,7 @@ import {
tryExtractTSExtension,
tryGetExtensionFromPath,
tryParsePatterns,
usesWildcardTypes,
Version,
version,
versionMajorMinor,
Expand Down Expand Up @@ -803,18 +806,17 @@ export function resolvePackageNameToPackageJson(
* Given a set of options, returns the set of type directive names
* that should be included for this program automatically.
* This list could either come from the config file,
* or from enumerating the types root + initial secondary types lookup location.
* and/or from enumerating the types root + initial secondary types lookup location given "*" compat wildcard.
* More type directives might appear in the program later as a result of loading actual source files;
* this list is only the set of defaults that are implicitly included.
*/
export function getAutomaticTypeDirectiveNames(options: CompilerOptions, host: ModuleResolutionHost): string[] {
// Use explicit type list from tsconfig.json
if (options.types) {
return options.types;
if (!usesWildcardTypes(options)) {
return options.types ?? [];
}

// Walk the primary type lookup locations
const result: string[] = [];
const wildcardMatches: string[] = [];
if (host.directoryExists && host.getDirectories) {
const typeRoots = getEffectiveTypeRoots(options, host);
if (typeRoots) {
Expand All @@ -833,15 +835,18 @@ export function getAutomaticTypeDirectiveNames(options: CompilerOptions, host: M
// At this stage, skip results with leading dot.
if (baseFileName.charCodeAt(0) !== CharacterCodes.dot) {
// Return just the type directive names
result.push(baseFileName);
wildcardMatches.push(baseFileName);
}
}
}
}
}
}
}
return result;

// Order potentially matters in program construction, so substitute
// in the wildcard in the position it was specified in the types array
return deduplicate(flatten(options.types.map(t => t === "*" ? wildcardMatches : t)), equateValues);
}

export interface TypeReferenceDirectiveResolutionCache extends PerDirectoryResolutionCache<ResolvedTypeReferenceDirectiveWithFailedLookupLocations>, NonRelativeNameResolutionCache<ResolvedTypeReferenceDirectiveWithFailedLookupLocations>, PackageJsonInfoCache {
Expand Down
5 changes: 3 additions & 2 deletions src/compiler/programDiagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
removeSuffix,
SourceFile,
TsConfigSourceFile,
usesWildcardTypes,
} from "./_namespaces/ts.js";

interface FileReasonToChainCache {
Expand Down Expand Up @@ -400,8 +401,8 @@ export function createProgramDiagnostics(getCompilerOptionsObjectLiteralSyntax:
) :
undefined;
case FileIncludeKind.AutomaticTypeDirectiveFile:
if (!options.types) return undefined;
configFileNode = getOptionsSyntaxByArrayElementValue(getCompilerOptionsObjectLiteralSyntax(), "types", reason.typeReference);
configFileNode = getOptionsSyntaxByArrayElementValue(getCompilerOptionsObjectLiteralSyntax(), "types", usesWildcardTypes(options) ? "*" : reason.typeReference);

message = Diagnostics.File_is_entry_point_of_type_library_specified_here;
break;
case FileIncludeKind.LibFile:
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/resolutionCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import {
StringLiteralLike,
trace,
updateResolutionField,
usesWildcardTypes,
WatchDirectoryFlags,
} from "./_namespaces/ts.js";

Expand Down Expand Up @@ -1667,7 +1668,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
*/
function updateTypeRootsWatch() {
const options = resolutionHost.getCompilationSettings();
if (options.types) {
if (!usesWildcardTypes(options)) {
// No need to do any watch since resolution cache is going to handle the failed lookups
// for the types added by this
closeTypeRootsWatch();
Expand Down
8 changes: 8 additions & 0 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8971,6 +8971,14 @@ export function importSyntaxAffectsModuleResolution(options: CompilerOptions): b
|| getResolvePackageJsonImports(options);
}

/**
* @internal
* Returns true if this option's types array includes "*"
*/
export function usesWildcardTypes(options: CompilerOptions): options is CompilerOptions & { types: string[]; } {
return some(options.types, t => t === "*");
}

type CompilerOptionKeys = keyof { [K in keyof CompilerOptions as string extends K ? never : K]: any; };
function createComputedCompilerOptions<T extends Record<string, CompilerOptionKeys[]>>(
options: {
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ import {
sourceMapCommentRegExpDontCareLineStart,
sys,
System,
usesWildcardTypes,
WatchCompilerHost,
WatchCompilerHostOfConfigFile,
WatchCompilerHostOfFilesAndCompilerOptions,
Expand Down Expand Up @@ -529,7 +530,7 @@ export function fileIncludeReasonToDiagnostics(program: Program, reason: FileInc
options.outFile ? "--outFile" : "--out",
);
case FileIncludeKind.AutomaticTypeDirectiveFile: {
const messageAndArgs: DiagnosticAndArguments = options.types ?
const messageAndArgs: DiagnosticAndArguments = !usesWildcardTypes(options) ?
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] :
Expand Down
3 changes: 2 additions & 1 deletion src/jsTyping/jsTyping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
some,
toFileNameLowerCase,
TypeAcquisition,
usesWildcardTypes,
Version,
versionMajorMinor,
} from "./_namespaces/ts.js";
Expand Down Expand Up @@ -133,7 +134,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 || usesWildcardTypes(compilerOptions)) {
const possibleSearchDirs = new Set(fileNames.map(getDirectoryPath));
possibleSearchDirs.add(projectRootPath);
possibleSearchDirs.forEach(searchDir => {
Expand Down
12 changes: 9 additions & 3 deletions src/services/codefixes/fixCannotFindModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const errorCannotFindImplicitJsxImport = Diagnostics.This_JSX_tag_requires_the_m
const errorCodes = [
errorCodeCannotFindModule,
Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type.code,
Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode.code,
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.code,
errorCannotFindImplicitJsxImport,
];
registerCodeFix({
Expand Down Expand Up @@ -77,7 +79,11 @@ function tryGetImportedPackageName(sourceFile: SourceFile, pos: number): string
}

function getTypesPackageNameToInstall(packageName: string, host: LanguageServiceHost, diagCode: number): string | undefined {
return diagCode === errorCodeCannotFindModule
? (nodeCoreModules.has(packageName) ? "@types/node" : undefined)
: (host.isKnownTypesPackageName?.(packageName) ? getTypesPackageName(packageName) : undefined);
if (nodeCoreModules.has(packageName)) {
return "@types/node";
}
if (diagCode !== errorCodeCannotFindModule) {
return host.isKnownTypesPackageName?.(packageName) ? getTypesPackageName(packageName) : undefined;
}
return undefined;
}
6 changes: 3 additions & 3 deletions src/testRunner/unittests/tsbuild/moduleResolution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ describe("unittests:: tsbuild:: moduleResolution:: handles the modules and optio
TestServerHost.createWatchedSystem({
"/home/src/workspaces/project/packages/pkg1_index.ts": `export const theNum: TheNum = "type1";`,
"/home/src/workspaces/project/packages/pkg1.tsconfig.json": jsonToReadableText({
compilerOptions: { composite: true, typeRoots: ["./typeroot1"] },
compilerOptions: { composite: true, typeRoots: ["./typeroot1"], types: ["*"] },
files: ["./pkg1_index.ts"],
}),
"/home/src/workspaces/project/packages/typeroot1/sometype/index.d.ts": dedent`declare type TheNum = "type1";`,
"/home/src/workspaces/project/packages/pkg2_index.ts": `export const theNum: TheNum2 = "type2";`,
"/home/src/workspaces/project/packages/pkg2.tsconfig.json": jsonToReadableText({
compilerOptions: { composite: true, typeRoots: ["./typeroot2"] },
compilerOptions: { composite: true, typeRoots: ["./typeroot2"], types: ["*"] },
files: ["./pkg2_index.ts"],
}),
"/home/src/workspaces/project/packages/typeroot2/sometype/index.d.ts": dedent`declare type TheNum2 = "type2";`,
Expand Down Expand Up @@ -163,7 +163,7 @@ describe("unittests:: tsbuild:: moduleResolution:: impliedNodeFormat differs bet
TestServerHost.createWatchedSystem({
"/home/src/workspaces/project/a/src/index.ts": "",
"/home/src/workspaces/project/a/tsconfig.json": jsonToReadableText({
compilerOptions: { strict: true },
compilerOptions: { strict: true, types: ["*"] },
}),
"/home/src/workspaces/project/b/src/index.ts": dedent`
import pg from "pg";
Expand Down
4 changes: 2 additions & 2 deletions src/testRunner/unittests/tsc/incremental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ declare global {
"/home/src/workspaces/project/node_modules/react/jsx-runtime.js": "export {}", // js needs to be present so there's a resolution result
"/home/src/workspaces/project/node_modules/@types/react/index.d.ts": getJsxLibraryContent(), // doesn't contain a jsx-runtime definition
"/home/src/workspaces/project/src/index.tsx": `export const App = () => <div propA={true}></div>;`,
"/home/src/workspaces/project/tsconfig.json": jsonToReadableText({ compilerOptions: { module: "commonjs", jsx: "react-jsx", incremental: true, jsxImportSource: "react" } }),
"/home/src/workspaces/project/tsconfig.json": jsonToReadableText({ compilerOptions: { module: "commonjs", jsx: "react-jsx", incremental: true, jsxImportSource: "react", types: ["react"] } }),
}),
commandLineArgs: ts.emptyArray,
});
Expand All @@ -201,7 +201,7 @@ declare global {
"/home/src/workspaces/project/node_modules/react/jsx-runtime.js": "export {}", // js needs to be present so there's a resolution result
"/home/src/workspaces/project/node_modules/@types/react/index.d.ts": getJsxLibraryContent(), // doesn't contain a jsx-runtime definition
"/home/src/workspaces/project/src/index.tsx": `export const App = () => <div propA={true}></div>;`,
"/home/src/workspaces/project/tsconfig.json": jsonToReadableText({ compilerOptions: { module: "commonjs", jsx: "react-jsx", incremental: true, jsxImportSource: "react" } }),
"/home/src/workspaces/project/tsconfig.json": jsonToReadableText({ compilerOptions: { module: "commonjs", jsx: "react-jsx", incremental: true, jsxImportSource: "react", types: ["react"] } }),
}),
commandLineArgs: ["--strict"],
});
Expand Down
10 changes: 7 additions & 3 deletions src/testRunner/unittests/tscWatch/resolutionCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ describe("unittests:: tscWatch:: resolutionCache:: tsc-watch module resolution c
verifyTscWatch({
scenario,
subScenario: "works when module resolution changes to ambient module",
commandLineArgs: ["-w", "/users/username/projects/project/foo.ts"],
commandLineArgs: ["-w", "/users/username/projects/project/foo.ts", "-types", "node"],
sys: () =>
TestServerHost.createWatchedSystem([{
path: "/users/username/projects/project/foo.ts",
Expand All @@ -263,6 +263,7 @@ declare module "fs" {
}
}`,
});
sys.runQueuedTimeoutCallbacks();
},
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
Expand Down Expand Up @@ -381,7 +382,10 @@ declare module "fs" {
edits: [
{
caption: "npm install",
edit: sys => sys.renameFolder(`/user/username/projects/myproject/node_modules2`, `/user/username/projects/myproject/node_modules`),
edit: sys => {
sys.renameFolder(`/user/username/projects/myproject/node_modules2`, `/user/username/projects/myproject/node_modules`);
sys.runQueuedTimeoutCallbacks();
},
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
],
Expand Down Expand Up @@ -565,7 +569,7 @@ declare namespace NodeJS {
};
const tsconfig: File = {
path: `/user/username/projects/myproject/tsconfig.json`,
content: "{}",
content: '{ "compilerOptions": { "types": ["*"] } }',
};
const { nodeAtTypesIndex, nodeAtTypesBase, nodeAtTypes36Base, nodeAtTypesGlobals } = getNodeAtTypes();
return TestServerHost.createWatchedSystem(
Expand Down
Loading
Loading