Implement default types=[] and wildcard support

- Modified getAutomaticTypeDirectiveNames to return empty array when types is undefined
- Added support for "*" wildcard value to opt into old "include all" behavior
- Created comprehensive test cases for new functionality

Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-01-21 23:18:01 +00:00
parent 4a9fccf76d
commit 2b70067c56
17 changed files with 303 additions and 1 deletions

View File

@ -810,7 +810,18 @@ export function resolvePackageNameToPackageJson(
export function getAutomaticTypeDirectiveNames(options: CompilerOptions, host: ModuleResolutionHost): string[] {
// Use explicit type list from tsconfig.json
if (options.types) {
return options.types;
// Check if the special "*" value is present, which means "include all"
if (options.types.length === 1 && options.types[0] === "*") {
// Fall through to enumerate all packages from typeRoots
}
else {
return options.types;
}
}
else {
// When types is undefined (not specified in tsconfig), default to empty array
// This is a breaking change from the previous behavior which included all @types packages
return emptyArray;
}
// Walk the primary type lookup locations

View File

@ -0,0 +1,18 @@
//// [tests/cases/compiler/typesOptionDefaultEmpty.ts] ////
//// [index.d.ts]
declare var $: { x: number };
//// [index.d.ts]
declare var _: { map: any };
//// [app.ts]
// With the new default behavior, @types packages are not automatically included
// unless explicitly listed in the types array or imported
const value = 42;
//// [app.js]
// With the new default behavior, @types packages are not automatically included
// unless explicitly listed in the types array or imported
var value = 42;

View File

@ -0,0 +1,8 @@
//// [tests/cases/compiler/typesOptionDefaultEmpty.ts] ////
=== /app.ts ===
// With the new default behavior, @types packages are not automatically included
// unless explicitly listed in the types array or imported
const value = 42;
>value : Symbol(value, Decl(app.ts, 2, 5))

View File

@ -0,0 +1 @@
[]

View File

@ -0,0 +1,11 @@
//// [tests/cases/compiler/typesOptionDefaultEmpty.ts] ////
=== /app.ts ===
// With the new default behavior, @types packages are not automatically included
// unless explicitly listed in the types array or imported
const value = 42;
>value : 42
> : ^^
>42 : 42
> : ^^

View File

@ -0,0 +1,21 @@
/app.ts(5,1): error TS2304: Cannot find name '_'.
==== /tsconfig.json (0 errors) ====
{ "compilerOptions": { "types": ["jquery"] } }
==== /app.ts (1 errors) ====
// With "types": ["jquery"], only jquery is included
$.x;
// lodash is not included, so this should error
_.map;
~
!!! error TS2304: Cannot find name '_'.
==== /node_modules/@types/jquery/index.d.ts (0 errors) ====
declare var $: { x: number };
==== /node_modules/@types/lodash/index.d.ts (0 errors) ====
declare var _: { map: any };

View File

@ -0,0 +1,21 @@
//// [tests/cases/compiler/typesOptionExplicitList.ts] ////
//// [index.d.ts]
declare var $: { x: number };
//// [index.d.ts]
declare var _: { map: any };
//// [app.ts]
// With "types": ["jquery"], only jquery is included
$.x;
// lodash is not included, so this should error
_.map;
//// [app.js]
// With "types": ["jquery"], only jquery is included
$.x;
// lodash is not included, so this should error
_.map;

View File

@ -0,0 +1,17 @@
//// [tests/cases/compiler/typesOptionExplicitList.ts] ////
=== /app.ts ===
// With "types": ["jquery"], only jquery is included
$.x;
>$.x : Symbol(x, Decl(index.d.ts, 0, 16))
>$ : Symbol($, Decl(index.d.ts, 0, 11))
>x : Symbol(x, Decl(index.d.ts, 0, 16))
// lodash is not included, so this should error
_.map;
=== /node_modules/@types/jquery/index.d.ts ===
declare var $: { x: number };
>$ : Symbol($, Decl(index.d.ts, 0, 11))
>x : Symbol(x, Decl(index.d.ts, 0, 16))

View File

@ -0,0 +1,12 @@
[
"======== Resolving type reference directive 'jquery', containing file '/__inferred type names__.ts', root directory '/node_modules/@types'. ========",
"Resolving with primary search path '/node_modules/@types'.",
"File '/node_modules/@types/jquery/package.json' does not exist.",
"File '/node_modules/@types/jquery/index.d.ts' exists - use it as a name resolution result.",
"Resolving real path for '/node_modules/@types/jquery/index.d.ts', result '/node_modules/@types/jquery/index.d.ts'.",
"======== Type reference directive 'jquery' was successfully resolved to '/node_modules/@types/jquery/index.d.ts', primary: true. ========",
"File '/node_modules/@types/jquery/package.json' does not exist according to earlier cached lookups.",
"File '/node_modules/@types/package.json' does not exist.",
"File '/node_modules/package.json' does not exist.",
"File '/package.json' does not exist."
]

View File

@ -0,0 +1,28 @@
//// [tests/cases/compiler/typesOptionExplicitList.ts] ////
=== /app.ts ===
// With "types": ["jquery"], only jquery is included
$.x;
>$.x : number
> : ^^^^^^
>$ : { x: number; }
> : ^^^^^ ^^^
>x : number
> : ^^^^^^
// lodash is not included, so this should error
_.map;
>_.map : any
> : ^^^
>_ : any
> : ^^^
>map : any
> : ^^^
=== /node_modules/@types/jquery/index.d.ts ===
declare var $: { x: number };
>$ : { x: number; }
> : ^^^^^ ^^^
>x : number
> : ^^^^^^

View File

@ -0,0 +1,20 @@
//// [tests/cases/compiler/typesOptionWildcard.ts] ////
//// [index.d.ts]
declare var $: { x: number };
//// [index.d.ts]
declare var _: { map: any };
//// [app.ts]
// With "types": ["*"], all @types packages are automatically included
// This is the opt-in to the old behavior
$.x;
_.map;
//// [app.js]
// With "types": ["*"], all @types packages are automatically included
// This is the opt-in to the old behavior
$.x;
_.map;

View File

@ -0,0 +1,25 @@
//// [tests/cases/compiler/typesOptionWildcard.ts] ////
=== /app.ts ===
// With "types": ["*"], all @types packages are automatically included
// This is the opt-in to the old behavior
$.x;
>$.x : Symbol(x, Decl(index.d.ts, 0, 16))
>$ : Symbol($, Decl(index.d.ts, 0, 11))
>x : Symbol(x, Decl(index.d.ts, 0, 16))
_.map;
>_.map : Symbol(map, Decl(index.d.ts, 0, 16))
>_ : Symbol(_, Decl(index.d.ts, 0, 11))
>map : Symbol(map, Decl(index.d.ts, 0, 16))
=== /node_modules/@types/jquery/index.d.ts ===
declare var $: { x: number };
>$ : Symbol($, Decl(index.d.ts, 0, 11))
>x : Symbol(x, Decl(index.d.ts, 0, 16))
=== /node_modules/@types/lodash/index.d.ts ===
declare var _: { map: any };
>_ : Symbol(_, Decl(index.d.ts, 0, 11))
>map : Symbol(map, Decl(index.d.ts, 0, 16))

View File

@ -0,0 +1,22 @@
[
"======== Resolving type reference directive 'jquery', containing file '/__inferred type names__.ts', root directory '/node_modules/@types'. ========",
"Resolving with primary search path '/node_modules/@types'.",
"File '/node_modules/@types/jquery/package.json' does not exist.",
"File '/node_modules/@types/jquery/index.d.ts' exists - use it as a name resolution result.",
"Resolving real path for '/node_modules/@types/jquery/index.d.ts', result '/node_modules/@types/jquery/index.d.ts'.",
"======== Type reference directive 'jquery' was successfully resolved to '/node_modules/@types/jquery/index.d.ts', primary: true. ========",
"======== Resolving type reference directive 'lodash', containing file '/__inferred type names__.ts', root directory '/node_modules/@types'. ========",
"Resolving with primary search path '/node_modules/@types'.",
"File '/node_modules/@types/lodash/package.json' does not exist.",
"File '/node_modules/@types/lodash/index.d.ts' exists - use it as a name resolution result.",
"Resolving real path for '/node_modules/@types/lodash/index.d.ts', result '/node_modules/@types/lodash/index.d.ts'.",
"======== Type reference directive 'lodash' was successfully resolved to '/node_modules/@types/lodash/index.d.ts', primary: true. ========",
"File '/node_modules/@types/jquery/package.json' does not exist according to earlier cached lookups.",
"File '/node_modules/@types/package.json' does not exist.",
"File '/node_modules/package.json' does not exist.",
"File '/package.json' does not exist.",
"File '/node_modules/@types/lodash/package.json' does not exist according to earlier cached lookups.",
"File '/node_modules/@types/package.json' does not exist according to earlier cached lookups.",
"File '/node_modules/package.json' does not exist according to earlier cached lookups.",
"File '/package.json' does not exist according to earlier cached lookups."
]

View File

@ -0,0 +1,33 @@
//// [tests/cases/compiler/typesOptionWildcard.ts] ////
=== /app.ts ===
// With "types": ["*"], all @types packages are automatically included
// This is the opt-in to the old behavior
$.x;
>$.x : number
> : ^^^^^^
>$ : { x: number; }
> : ^^^^^ ^^^
>x : number
> : ^^^^^^
_.map;
>_.map : any
>_ : { map: any; }
> : ^^^^^^^ ^^^
>map : any
> : ^^^
=== /node_modules/@types/jquery/index.d.ts ===
declare var $: { x: number };
>$ : { x: number; }
> : ^^^^^ ^^^
>x : number
> : ^^^^^^
=== /node_modules/@types/lodash/index.d.ts ===
declare var _: { map: any };
>_ : { map: any; }
> : ^^^^^^^ ^^^
>map : any

View File

@ -0,0 +1,17 @@
// @traceResolution: true
// @noImplicitReferences: true
// @currentDirectory: /
// @filename: /tsconfig.json
{}
// @filename: /node_modules/@types/jquery/index.d.ts
declare var $: { x: number };
// @filename: /node_modules/@types/lodash/index.d.ts
declare var _: { map: any };
// @filename: /app.ts
// With the new default behavior, @types packages are not automatically included
// unless explicitly listed in the types array or imported
const value = 42;

View File

@ -0,0 +1,19 @@
// @traceResolution: true
// @noImplicitReferences: true
// @currentDirectory: /
// @filename: /tsconfig.json
{ "compilerOptions": { "types": ["jquery"] } }
// @filename: /node_modules/@types/jquery/index.d.ts
declare var $: { x: number };
// @filename: /node_modules/@types/lodash/index.d.ts
declare var _: { map: any };
// @filename: /app.ts
// With "types": ["jquery"], only jquery is included
$.x;
// lodash is not included, so this should error
_.map;

View File

@ -0,0 +1,18 @@
// @traceResolution: true
// @noImplicitReferences: true
// @currentDirectory: /
// @filename: /tsconfig.json
{ "compilerOptions": { "types": ["*"] } }
// @filename: /node_modules/@types/jquery/index.d.ts
declare var $: { x: number };
// @filename: /node_modules/@types/lodash/index.d.ts
declare var _: { map: any };
// @filename: /app.ts
// With "types": ["*"], all @types packages are automatically included
// This is the opt-in to the old behavior
$.x;
_.map;