Skip to content

Commit 790cee2

Browse files
committed
fix(types): narrow down the return type of defineConfig
Fixes compatibility with `mergeConfig`, as reported in vuejs/create-vue#313 Before the change, `defineConfig` would return `UserConfigExport`, which is a union type. This would cause `mergeConfig` to fail, as it doesn't accept the `UserConfigFn` type in the union. (vitejs#13135) After the change, `defineConfig` returns the same type that it receives, so it would exclude `UserConfigFn` from the return type whenever possible.
1 parent ec9d2e7 commit 790cee2

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

packages/vite/src/node/__tests__/config.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { mergeConfig } from '../publicUtils'
77

88
describe('mergeConfig', () => {
99
test('handles configs with different alias schemas', () => {
10-
const baseConfig: UserConfigExport = {
10+
const baseConfig = defineConfig({
1111
resolve: {
1212
alias: [
1313
{
@@ -16,16 +16,16 @@ describe('mergeConfig', () => {
1616
},
1717
],
1818
},
19-
}
19+
})
2020

21-
const newConfig: UserConfigExport = {
21+
const newConfig = defineConfig({
2222
resolve: {
2323
alias: {
2424
bar: 'bar-value',
2525
baz: 'baz-value',
2626
},
2727
},
28-
}
28+
})
2929

3030
const mergedConfig: UserConfigExport = {
3131
resolve: {

packages/vite/src/node/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export type UserConfigExport = UserConfig | Promise<UserConfig> | UserConfigFn
109109
* The function receives a {@link ConfigEnv} object that exposes two properties:
110110
* `command` (either `'build'` or `'serve'`), and `mode`.
111111
*/
112-
export function defineConfig(config: UserConfigExport): UserConfigExport {
112+
export function defineConfig<T extends UserConfigExport>(config: T): T {
113113
return config
114114
}
115115

0 commit comments

Comments
 (0)