Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 21, 2026

Implementation Complete: Change default of types to [] in TypeScript 6.0

✅ All Requirements Met

Breaking Change: The types compiler option now defaults to [] (empty array) instead of automatically including all packages from node_modules/@types.

Core Changes

1. Modified getAutomaticTypeDirectiveNames in src/compiler/moduleNameResolver.ts

  • Returns empty array when types is undefined (new default)
  • Supports "*" wildcard to include all @types packages
  • Supports mixing wildcard with explicit types for gradual migration
  • Refactored with early return for clarity

2. New Test Cases (4 tests)

  • typesOptionDefaultEmpty.ts - Validates new empty default behavior
  • typesOptionWildcard.ts - Validates "types": ["*"] includes all
  • typesOptionExplicitList.ts - Validates explicit types list works
  • typesOptionWildcardWithExplicit.ts - Validates mixed wildcard + explicit types

3. Updated 11 Existing Tests

  • Added explicit types arrays to tests relying on automatic inclusion
  • Updated 119 test baselines reflecting new default behavior

Migration Patterns

Option 1: Explicit types (recommended)

{
  "compilerOptions": {
    "types": ["node", "jest"]
  }
}

Option 2: Gradual migration

{
  "compilerOptions": {
    "types": ["*", "node", "jest"]  // "*" for now, remove later
  }
}

Option 3: Keep old behavior

{
  "compilerOptions": {
    "types": ["*"]
  }
}

Test Results

All tests passing
Linter passed
Formatter passed

Impact

This change improves build performance by 20-50% for projects that were inadvertently including hundreds of unused @types packages.

Original prompt

This section details on the original issue you should resolve

<issue_title>Change default of types to [] in tsconfig.json</issue_title>
<issue_description>In 6.0, we plan to disable automatic inclusion of every file in node_modules/@types. In 6.0, these packages will need to be brought in via imports, or explicitly listed in your tsconfig.json's types.

{
    "compilerOptions": {
        // ...

        // ℹ️ Packages with globals go here now!
        "types": [
            "node",
            "mocha",
            "jest",
            "jasmine",
            "...",
        ],
    }
}

To opt into the old auto-inclusion behavior, we will need an explicit opt-in. We are thinking that this could just be the presence of an entry like "*" in the types array.

{
    "compilerOptions": {
        "types": ["*"],
    }
}

This can make migration easier, as developers can easily keep/remove the "*", and add entries to the list as they are encountered

{
    "compilerOptions": {
        "types": [
            "*", // Temporarily necessary for 6.0/7.0 upgrade.
            "other",
            "globals",
            "go",
            "here"
        ],
    }
}

[!IMPORTANT]
Read the above carefully - this does not mean we will stop reading from node_modules/@types, just that the files won't be brought in unless

  • imported
  • explicitly listed in your tsconfig.json's types array.
  • brought in with /// <reference types="..." /> (please try to avoid doing this)

Typically this will only affect users relying on global values and module names, like those brought in from @types/node (e.g. the "fs" module is globally defined), or a testing framework.


More rationale from #54500:

Currently, the types value defaults to "enumerate everything in node_modules/@types". This is potentially very expensive as a normal repo setup these days might transitively pull in hundreds of @types packages. Modern projects almost always need only @types/node, @types/jest, or a handful of other common global-affecting packages.

In 6.0, the default types value will be [].
This will affect many projects; you will likely need to add "types": ["node"] or a few others.

This will prevent projects from unintentionally pulling in hundreds or even thousands of unneeded declaration files at build time. Many projects we've looked at have improved their build time anywhere from 20-50% just by setting types appropriately.</issue_description>

Comments on the Issue (you are @copilot in this section)

@jakebailey A gotcha here is that there's no config that means "include all", because unset means "include none", `null` means "behave like unset". So, we will also need to introduce a new way to indicate "include everything" like `"types": ["*"]` or decide to not have that behavior at all. @DanielRosenwasser @jakebailey folded that into the write-up. @jakebailey No, it would not. That still requires multiple configs.

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@typescript-bot typescript-bot added For Milestone Bug PRs that fix a bug with a specific milestone labels Jan 21, 2026
Copilot AI and others added 4 commits January 21, 2026 23:18
- 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>
Updated tests to explicitly specify types they depend on:
- Added "types": ["node"] to tests requiring @types/node
- Added "types": ["react"] to tests requiring @types/react
- Added "types": ["classnames"] to UMD module tests
- Added "types": ["*"] to external project test to maintain old behavior
- Fixed autoImportPackageJsonFilterExistingImport3 test structure

Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
All tests passing with new types default behavior

Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
- Enhanced wildcard logic to support mixing "*" with explicit types
- Added test for wildcard combined with explicit types
- This supports gradual migration pattern: types: ["*", "node", "jest"]
- All 99,255 tests passing

Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Copilot AI changed the title [WIP] Change default of types to empty array in tsconfig.json Change default of types to [] in tsconfig.json Jan 22, 2026
Copilot AI requested a review from RyanCavanaugh January 22, 2026 00:04
Copy link
Member

@RyanCavanaugh RyanCavanaugh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot pls fix

- Early return when hasWildcard is false
- Remove explanatory comments as code is self-documenting
- Addresses code review feedback

Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
@jakebailey
Copy link
Member

Annoyingly the use of * means it's not easy for a potential twoslash comment to target it, since * is for variants, but, I don't even think twoslash supports types anyway

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Milestone Bug PRs that fix a bug with a specific milestone

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change default of types to [] in tsconfig.json

4 participants