Skip to content

Change type extensions handling#8191

Open
alcuadrado wants to merge 8 commits intomainfrom
change-type-extensions-handling
Open

Change type extensions handling#8191
alcuadrado wants to merge 8 commits intomainfrom
change-type-extensions-handling

Conversation

@alcuadrado
Copy link
Copy Markdown
Member

@alcuadrado alcuadrado commented Apr 24, 2026

This is the first change to complete this:

It reworked how we handle type-extensions preventing Hardhat from importing every single type files. It currently only imports the ones with enums.

@alcuadrado alcuadrado requested review from Copilot and kanej April 24, 2026 22:10
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 24, 2026

🦋 Changeset detected

Latest commit: 2a4ae8e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 17 packages
Name Type
@nomicfoundation/hardhat-ethers-chai-matchers Patch
@nomicfoundation/hardhat-ethers Patch
@nomicfoundation/hardhat-ignition-ethers Patch
@nomicfoundation/hardhat-ignition Patch
@nomicfoundation/hardhat-ignition-viem Patch
@nomicfoundation/hardhat-keystore Patch
@nomicfoundation/hardhat-ledger Patch
@nomicfoundation/hardhat-mocha Patch
@nomicfoundation/hardhat-network-helpers Patch
@nomicfoundation/hardhat-node-test-runner Patch
@nomicfoundation/hardhat-toolbox-mocha-ethers Patch
@nomicfoundation/hardhat-toolbox-viem Patch
@nomicfoundation/hardhat-typechain Patch
hardhat Patch
@nomicfoundation/hardhat-verify Patch
@nomicfoundation/hardhat-viem-assertions Patch
@nomicfoundation/hardhat-viem Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors Hardhat and its official plugins to load TypeScript type extensions via export type * re-exports instead of runtime imports, so compiled JavaScript no longer executes unnecessary type-extension imports.

Changes:

  • Replace runtime import "./type-extensions.js" patterns with export type * from "./type-extensions.js" across built-in and external plugins.
  • Remove side-effect-only imports inside type-extension files, relying on module augmentation without runtime loading.
  • Update the shared TS config to force module detection (moduleDetection: "force") to support augmentation-only modules.

Reviewed changes

Copilot reviewed 54 out of 56 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/hardhat/src/types/plugins.ts Switches built-in type-extension loading to a type-only re-export.
packages/hardhat/src/types/config.ts Removes built-in plugin import from the hardhat/types/config entry point.
packages/hardhat/src/internal/builtin-plugins/test/type-extensions.ts Removes side-effect import from test plugin type extensions.
packages/hardhat/src/internal/builtin-plugins/test/index.ts Uses type-only re-export to load type extensions without runtime import.
packages/hardhat/src/internal/builtin-plugins/solidity/type-extensions.ts Removes multiple side-effect imports; relies on module augmentation.
packages/hardhat/src/internal/builtin-plugins/solidity/index.ts Uses type-only re-export to load type extensions without runtime import.
packages/hardhat/src/internal/builtin-plugins/solidity-test/type-extensions.ts Removes side-effect import from solidity-test plugin type extensions.
packages/hardhat/src/internal/builtin-plugins/solidity-test/index.ts Uses type-only re-export to load type extensions without runtime import.
packages/hardhat/src/internal/builtin-plugins/network-manager/type-extensions/hre.ts Removes side-effect import from HRE type extension.
packages/hardhat/src/internal/builtin-plugins/network-manager/type-extensions/hooks.ts Removes side-effect import from hooks type extension.
packages/hardhat/src/internal/builtin-plugins/network-manager/type-extensions/global-options.ts Removes side-effect import from global-options type extension.
packages/hardhat/src/internal/builtin-plugins/network-manager/type-extensions/config.ts Removes side-effect import from config type extension.
packages/hardhat/src/internal/builtin-plugins/network-manager/index.ts Uses type-only re-exports for each type-extension module.
packages/hardhat/src/internal/builtin-plugins/index.ts Centralizes type-only re-exports to ensure built-in type extensions are reachable.
packages/hardhat/src/internal/builtin-plugins/gas-analytics/type-extensions.ts Removes side-effect import from gas-analytics type extensions.
packages/hardhat/src/internal/builtin-plugins/gas-analytics/index.ts Uses type-only re-export to load type extensions without runtime import.
packages/hardhat/src/internal/builtin-plugins/coverage/type-extensions.ts Removes side-effect import from coverage type extensions.
packages/hardhat/src/internal/builtin-plugins/coverage/index.ts Uses type-only re-export to load type extensions without runtime import.
packages/hardhat/src/internal/builtin-plugins/clean/type-extensions.ts Removes side-effect import from clean type extensions.
packages/hardhat/src/internal/builtin-plugins/clean/index.ts Uses type-only re-export to load type extensions without runtime import.
packages/hardhat/src/internal/builtin-plugins/artifacts/index.ts Uses type-only re-export to load type extensions without runtime import.
packages/hardhat/src/index.ts Loads built-in type extensions via type-only re-export instead of runtime import.
packages/hardhat/src/hre.ts Loads built-in type extensions via type-only re-export instead of runtime import.
packages/hardhat/src/config.ts Loads built-in type extensions via type-only re-export instead of runtime import.
packages/hardhat-viem/src/type-extensions.ts Removes side-effect import from type extensions.
packages/hardhat-viem/src/index.ts Uses type-only re-export to load type extensions without runtime import.
packages/hardhat-viem-assertions/src/type-extensions.ts Replaces runtime dependency import with type-only re-export.
packages/hardhat-viem-assertions/src/index.ts Uses type-only re-export to load type extensions without runtime import.
packages/hardhat-verify/src/type-extensions.ts Removes side-effect imports from type extensions.
packages/hardhat-verify/src/index.ts Uses type-only re-export to load type extensions without runtime import.
packages/hardhat-typechain/src/type-extensions.ts Adds type-only re-export of dependency and removes side-effect imports.
packages/hardhat-typechain/src/index.ts Uses type-only re-export to load type extensions without runtime import.
packages/hardhat-toolbox-viem/src/index.ts Uses type-only re-export to load type extensions without runtime import.
packages/hardhat-toolbox-mocha-ethers/src/index.ts Uses type-only re-export to load type extensions without runtime import.
packages/hardhat-solx/src/type-extensions.ts Removes side-effect import from type extensions.
packages/hardhat-solx/src/index.ts Uses type-only re-export to load type extensions without runtime import.
packages/hardhat-node-test-runner/src/type-extensions.ts Removes side-effect import from type extensions.
packages/hardhat-node-test-runner/src/index.ts Uses type-only re-export to load type extensions without runtime import.
packages/hardhat-network-helpers/src/type-extensions.ts Removes side-effect import from type extensions.
packages/hardhat-network-helpers/src/index.ts Uses type-only re-export to load type extensions without runtime import.
packages/hardhat-mocha/src/type-extensions.ts Removes side-effect imports from type extensions.
packages/hardhat-mocha/src/index.ts Uses type-only re-export to load type extensions without runtime import.
packages/hardhat-ledger/src/type-extensions.ts Removes side-effect import from type extensions.
packages/hardhat-ledger/src/index.ts Uses type-only re-export to load type extensions without runtime import.
packages/hardhat-keystore/src/internal/type-extensions.ts Removes side-effect import from type extensions.
packages/hardhat-keystore/src/index.ts Uses type-only re-export to load type extensions without runtime import.
packages/hardhat-ignition/src/type-extensions.ts Removes side-effect import and adds type-only dependency re-export.
packages/hardhat-ignition/src/index.ts Uses type-only re-export to load type extensions without runtime import.
packages/hardhat-ignition-viem/src/index.ts Uses type-only re-export to load type extensions without runtime import.
packages/hardhat-ignition-ethers/src/internal/ethers-ignition-helper.ts Removes runtime-only dependency imports from helper implementation.
packages/hardhat-ignition-ethers/src/index.ts Uses type-only re-export to load type extensions without runtime import.
packages/hardhat-ethers/src/type-extensions.ts Removes side-effect import from type extensions.
packages/hardhat-ethers/src/index.ts Uses type-only re-export to load type extensions without runtime import.
packages/hardhat-ethers-chai-matchers/src/type-extensions.ts Adds type-only dependency re-export to ensure dependent augmentations load.
packages/hardhat-ethers-chai-matchers/src/index.ts Uses type-only re-export to load type extensions without runtime import.
packages/config/tsconfig.base.json Forces module detection to support augmentation-only modules.
Comments suppressed due to low confidence (1)

packages/hardhat/src/types/config.ts:5

  • hardhat/types/config no longer references the built-in plugins, so importing this entry point will stop applying the built-in type extensions (e.g. the solidity, network, etc config augmentations). Since ./types/config is a published export (see packages/hardhat/package.json), this looks like a breaking change for users who import HardhatUserConfig from hardhat/types/config. Consider adding a type-only re-export (similar to types/plugins.ts) so built-in config extensions are still loaded without introducing runtime imports, or otherwise ensure hardhat/types/config continues to include built-in augmentations.

Base automatically changed from optimize-true-case-path to main April 28, 2026 17:36
@alcuadrado alcuadrado added the no docs needed This PR doesn't require links to documentation label Apr 29, 2026
@alcuadrado
Copy link
Copy Markdown
Member Author

Added 'no docs needed", the docs chnges are in the plugin development guide, and tracked by an issue.

Previously, we recommended users to import 'hardhat/types/config'
directly in their config, so that was the place where we loaded the
built-in plugin types.

Now we recommend importing `hardhat/config`'s `defineConfig` function,
so we need to load the built-in plugin's type extensions there.

We removed the `export type *` from `types/config`, because otherwise we
have a circular dependency between it and the built-in plugin
extensions, which breaks them.
@alcuadrado alcuadrado force-pushed the change-type-extensions-handling branch from fe35923 to e2bc2e3 Compare April 29, 2026 15:17
@alcuadrado alcuadrado force-pushed the change-type-extensions-handling branch from e2bc2e3 to 2a4ae8e Compare April 29, 2026 15:52
Copilot AI review requested due to automatic review settings April 29, 2026 15:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 71 out of 73 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

packages/hardhat/src/types/config.ts:5

  • hardhat/types/config no longer ensures that built-in plugin type-extensions are part of the type graph (previously done via importing ../internal/builtin-plugins/index.js). This can regress users that only do import type { HardhatUserConfig } from "hardhat/types/config" (e.g. in hardhat.config.ts) because built-in config fields like solidity, networks, plugins, etc. may disappear unless they also import hardhat/config or hardhat/types/plugins. Consider adding a type-only re-export here (e.g. export type * from "../internal/builtin-plugins/index.js";) to preserve the old behavior without introducing runtime imports.

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

Labels

no docs needed This PR doesn't require links to documentation no peer bump needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants