fix(types): improve defineConfig callback inference#21699
Closed
Vishnuuuu24 wants to merge 2 commits intovitejs:mainfrom
Closed
fix(types): improve defineConfig callback inference#21699Vishnuuuu24 wants to merge 2 commits intovitejs:mainfrom
Vishnuuuu24 wants to merge 2 commits intovitejs:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a TypeScript type inference issue where using defineConfig with async callbacks caused literal option types (like build.minify: 'terser') to be widened to string, resulting in TS2769 errors.
Changes:
- Refactored
defineConfigoverloads to use a generic callback-first signature that preserves literal types - Added comprehensive dts regression tests for sync/async callbacks with minify literals
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/vite/src/node/config.ts | Replaced three function overloads with a single generic overload that preserves literal types using conditional return types |
| packages/vite/src/node/tests_dts/config.ts | Added three test cases validating literal type preservation in sync/async callbacks and invalid option detection |
sapphi-red
reviewed
Feb 24, 2026
Author
|
Thanks for calling this out. You’re right, I used AI assistance while preparing this PR and parts ended up too close to #21698, including test shape and the proxy-bypass point you had already identified. I should have explicitly credited your prior work. Sorry about that, and thanks for the review. |
Author
|
Thanks for pointing this out. I used AI assistance while preparing this PR,
and the result ended up too close to your draft in #21698 (including the
same test shape and the proxy-bypass workaround you had already called
out). I should have explicitly referenced your prior work. Sorry about
that, and thanks for the review, will make the required changes soon.
…On Tue, 24 Feb 2026 at 18:27, 翠 ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In packages/vite/src/node/__tests_dts__/config.ts
<#21699 (comment)>:
> @@ -37,6 +37,28 @@ defineConfig({
unknownProperty: 1,
})
+defineConfig(() => ({
+ base: '',
+ build: {
+ minify: 'oxc',
+ },
+}))
+
+defineConfig(async () => ({
+ base: '',
+ build: {
+ minify: 'terser',
+ },
+}))
+
+// @ts-expect-error --- nested invalid option `build.unknown` should error
I suspect you copied this part of code from my PR
<#21698>. It's too similar to believe
that it's a coincidence. If that's the case, I'd suggest at least
mentioning it.
------------------------------
In playground/proxy-bypass/vite.config.js
<#21699 (comment)>:
> @@ -9,7 +9,7 @@ export default defineConfig({
'/nonExistentApp': {
target: 'http://localhost:9607',
bypass: () => {
- return false
+ return /** @type {false} */ (false)
This is the breakage I mentioned at #21698 (comment)
<#21698 (comment)>
—
Reply to this email directly, view it on GitHub
<#21699 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BAXYJBQVEWT4QZUU4EYYLB34NRDCLAVCNFSM6AAAAACV5ZPKNGVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTQNBXG4YTSNZVGY>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
defineConfigcallback overload inference so sync/async callback configs preserve literal option typesbuild.minify: 'terser'were widened and triggered TS2769as constDetails
defineConfigoverloads inpackages/vite/src/node/config.tsto use a callback-first generic signature:defineConfig<T extends UserConfigFn>(config: T & UserConfigFn): ...UserConfigFnObject/UserConfigFnPromise/UserConfigFnexpectationspackages/vite/src/node/__tests_dts__/config.ts:build.minify: 'oxc'build.minify: 'terser'build.unknownstill errors (@ts-expect-error)Validation
pnpm run build-types-checkpnpm run typecheckRefs #21684