Skip to content

Conversation

@alcuadrado
Copy link
Member

@alcuadrado alcuadrado commented Sep 22, 2025

This is an idea that @fvictorio had, based on eslint, but also used by astro.

Instead of letting the user do:

import type { HardhatUserConfig } from "hardhat/config";

const config: HardhatUserConfig = {};

export default config;

we can have a defineConfig function so it's just:

import { defineConfig } from "hardhat/config";

export default defineConfig({});

which is shorter, type-safe, and has autocomplete on javascript too (!)

Note: we can't use defineConfig in our own tests, because we use --isolatedDeclarations. I added a comment about it to the tsdoc of the function.

Documentation update: NomicFoundation/hardhat-website#125

@alcuadrado alcuadrado requested a review from Copilot September 22, 2025 18:46
@changeset-bot
Copy link

changeset-bot bot commented Sep 22, 2025

🦋 Changeset detected

Latest commit: 7774d44

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

This PR includes changesets to release 19 packages
Name Type
hardhat Patch
@nomicfoundation/hardhat-ethers-chai-matchers Patch
@nomicfoundation/hardhat-toolbox-mocha-ethers Patch
@nomicfoundation/hardhat-node-test-runner Patch
@nomicfoundation/hardhat-ignition-ethers Patch
@nomicfoundation/hardhat-network-helpers Patch
@nomicfoundation/hardhat-viem-assertions Patch
@nomicfoundation/hardhat-ignition-viem Patch
@nomicfoundation/hardhat-toolbox-viem Patch
@nomicfoundation/hardhat-typechain Patch
@nomicfoundation/hardhat-ignition Patch
@nomicfoundation/hardhat-keystore Patch
@nomicfoundation/hardhat-ethers Patch
@nomicfoundation/hardhat-ledger Patch
@nomicfoundation/hardhat-verify Patch
@nomicfoundation/hardhat-mocha Patch
@nomicfoundation/hardhat-viem Patch
@nomicfoundation/ignition-core Patch
@nomicfoundation/ignition-ui 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
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

This PR introduces a defineConfig helper function to the Hardhat configuration API, providing a more ergonomic way to define Hardhat configurations with better type safety and autocomplete support for both TypeScript and JavaScript users.

Key changes:

  • Adds defineConfig function to hardhat/config that wraps configuration objects
  • Updates template files to use the new defineConfig pattern instead of explicit type annotations
  • Provides comprehensive JSDoc documentation explaining usage and limitations

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
v-next/hardhat/src/config.ts Implements the defineConfig function with type safety and documentation
v-next/hardhat/templates/hardhat-3/02-mocha-ethers/hardhat.config.ts Updates template to use defineConfig pattern
v-next/hardhat/templates/hardhat-3/01-node-test-runner-viem/hardhat.config.ts Updates template to use defineConfig pattern
v-next/example-project/hardhat.config.ts Updates example project to demonstrate defineConfig usage

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@michalbrabec michalbrabec self-requested a review September 23, 2025 09:55
@alcuadrado
Copy link
Member Author

I initially thought this wasn't going to work, as the template packages needs to point to the newest version of hardhat. But turns out that changesets also bumps the version range in the template packages :)

I added a PR to the website that needs to be merged once this is released.

Also, I updated the readmes of all the packages. I don't think this requires bumping their peerDependency on hardhat, as it's just a documentation doc. /cc @kanej

@alcuadrado alcuadrado requested a review from Copilot November 2, 2025 23:07
@alcuadrado
Copy link
Member Author

@michalbrabec this can be re-reviewed now.

Copy link
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 21 out of 21 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@alcuadrado
Copy link
Member Author

Also, after releasing this we should update the branches main and tutorial of https://github.com/NomicFoundation/hardhat3-plugin-template, but it can't be done yet.

@alcuadrado alcuadrado added this pull request to the merge queue Nov 3, 2025
Merged via the queue into main with commit 499374e Nov 3, 2025
201 checks passed
@alcuadrado alcuadrado deleted the defineConfig branch November 3, 2025 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants