From 203801f864e2a067eb7820332bca941d9af41c64 Mon Sep 17 00:00:00 2001 From: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Date: Tue, 24 Feb 2026 14:44:35 +0900 Subject: [PATCH 1/2] feat: allow `defineConfig` with callback without `as const` --- .../vite/src/node/__tests_dts__/config.ts | 37 ++++++++++++++++++- packages/vite/src/node/config.ts | 12 ++++-- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/packages/vite/src/node/__tests_dts__/config.ts b/packages/vite/src/node/__tests_dts__/config.ts index a6a6498d3ef304..891ec216d2acbe 100644 --- a/packages/vite/src/node/__tests_dts__/config.ts +++ b/packages/vite/src/node/__tests_dts__/config.ts @@ -33,10 +33,45 @@ export type cases1 = [ defineConfig({ base: '', - // @ts-expect-error + build: { + minify: 'oxc', // `as const` is not needed + }, + // @ts-expect-error --- invalid option should error unknownProperty: 1, }) +defineConfig(() => ({ + base: '', + build: { + minify: 'oxc', // `as const` is not needed + }, + unknownProperty: 1, // we cannot catch invalid option for this case, ideally we should +})) + +// @ts-expect-error --- nested invalid option `build.unknown` should error +defineConfig(() => ({ + base: '', + build: { + unknown: 1, + }, +})) + +defineConfig(async () => ({ + base: '', + build: { + minify: 'oxc', // `as const` is not needed + }, + unknownProperty: 1, // we cannot catch invalid option for this case, ideally we should +})) + +// @ts-expect-error --- nested invalid option `build.unknown` should error +defineConfig(async () => ({ + base: '', + build: { + unknown: 1, + }, +})) + mergeConfig(defineConfig({}), defineConfig({})) mergeConfig( // @ts-expect-error diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index d45c6372f7d77b..3cbaefbc9037ed 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -172,11 +172,15 @@ export type UserConfigExport = * accepts a direct {@link UserConfig} object, or a function that returns it. * The function receives a {@link ConfigEnv} object. */ -export function defineConfig(config: UserConfig): UserConfig +export function defineConfig( + config: T, +): T extends UserConfigFnObject + ? UserConfigFnObject + : T extends UserConfigFnPromise + ? UserConfigFnPromise + : UserConfigFn export function defineConfig(config: Promise): Promise -export function defineConfig(config: UserConfigFnObject): UserConfigFnObject -export function defineConfig(config: UserConfigFnPromise): UserConfigFnPromise -export function defineConfig(config: UserConfigFn): UserConfigFn +export function defineConfig(config: UserConfig): UserConfig export function defineConfig(config: UserConfigExport): UserConfigExport export function defineConfig(config: UserConfigExport): UserConfigExport { return config From 15cfebed6def8f1c81737c4dc8be67a63d204acd Mon Sep 17 00:00:00 2001 From: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Date: Tue, 24 Feb 2026 15:21:27 +0900 Subject: [PATCH 2/2] chore: revert --- .../vite/src/node/__tests_dts__/config.ts | 25 +++++++++++++++++-- packages/vite/src/node/config.ts | 12 +++------ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/packages/vite/src/node/__tests_dts__/config.ts b/packages/vite/src/node/__tests_dts__/config.ts index 891ec216d2acbe..35b2542eb20352 100644 --- a/packages/vite/src/node/__tests_dts__/config.ts +++ b/packages/vite/src/node/__tests_dts__/config.ts @@ -36,6 +36,13 @@ defineConfig({ build: { minify: 'oxc', // `as const` is not needed }, + server: { + proxy: { + '/test': { + bypass: () => false, + }, + }, + }, // @ts-expect-error --- invalid option should error unknownProperty: 1, }) @@ -43,7 +50,14 @@ defineConfig({ defineConfig(() => ({ base: '', build: { - minify: 'oxc', // `as const` is not needed + minify: 'oxc' as const, // ideally we don't want to require `as const` here + }, + server: { + proxy: { + '/test': { + bypass: () => false as const, // ideally we don't want to require `as const` here + }, + }, }, unknownProperty: 1, // we cannot catch invalid option for this case, ideally we should })) @@ -59,7 +73,14 @@ defineConfig(() => ({ defineConfig(async () => ({ base: '', build: { - minify: 'oxc', // `as const` is not needed + minify: 'oxc' as const, // ideally we don't want to require `as const` here + }, + server: { + proxy: { + '/test': { + bypass: () => false as const, // ideally we don't want to require `as const` here + }, + }, }, unknownProperty: 1, // we cannot catch invalid option for this case, ideally we should })) diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index 3cbaefbc9037ed..d45c6372f7d77b 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -172,15 +172,11 @@ export type UserConfigExport = * accepts a direct {@link UserConfig} object, or a function that returns it. * The function receives a {@link ConfigEnv} object. */ -export function defineConfig( - config: T, -): T extends UserConfigFnObject - ? UserConfigFnObject - : T extends UserConfigFnPromise - ? UserConfigFnPromise - : UserConfigFn -export function defineConfig(config: Promise): Promise export function defineConfig(config: UserConfig): UserConfig +export function defineConfig(config: Promise): Promise +export function defineConfig(config: UserConfigFnObject): UserConfigFnObject +export function defineConfig(config: UserConfigFnPromise): UserConfigFnPromise +export function defineConfig(config: UserConfigFn): UserConfigFn export function defineConfig(config: UserConfigExport): UserConfigExport export function defineConfig(config: UserConfigExport): UserConfigExport { return config