Skip to content

Commit 94e34cf

Browse files
authored
fix(types): add more overload to defineConfig (#18299)
1 parent 466f94a commit 94e34cf

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* eslint-disable @typescript-eslint/ban-ts-comment */
2+
/* eslint-disable @typescript-eslint/no-unused-vars */
3+
import type { Equal, ExpectTrue } from '@type-challenges/utils'
4+
import {
5+
type UserConfig,
6+
type UserConfigExport,
7+
type UserConfigFn,
8+
type UserConfigFnObject,
9+
type UserConfigFnPromise,
10+
defineConfig,
11+
} from '../config'
12+
import { mergeConfig } from '../publicUtils'
13+
14+
const configObjectDefined = defineConfig({})
15+
const configObjectPromiseDefined = defineConfig(Promise.resolve({}))
16+
const configFnObjectDefined = defineConfig(() => ({}))
17+
const configFnPromiseDefined = defineConfig(async () => ({}))
18+
const configFnDefined = defineConfig(() =>
19+
// TypeScript requires both non-promise config and
20+
// promise config to have at least one property
21+
Math.random() > 0.5 ? { base: '' } : Promise.resolve({ base: '/' }),
22+
)
23+
const configExportDefined = defineConfig({} as UserConfigExport)
24+
25+
export type cases1 = [
26+
ExpectTrue<Equal<typeof configObjectDefined, UserConfig>>,
27+
ExpectTrue<Equal<typeof configObjectPromiseDefined, Promise<UserConfig>>>,
28+
ExpectTrue<Equal<typeof configFnObjectDefined, UserConfigFnObject>>,
29+
ExpectTrue<Equal<typeof configFnPromiseDefined, UserConfigFnPromise>>,
30+
ExpectTrue<Equal<typeof configFnDefined, UserConfigFn>>,
31+
ExpectTrue<Equal<typeof configExportDefined, UserConfigExport>>,
32+
]
33+
34+
defineConfig({
35+
base: '',
36+
// @ts-expect-error
37+
unknownProperty: 1,
38+
})
39+
40+
mergeConfig(defineConfig({}), defineConfig({}))
41+
mergeConfig(
42+
// @ts-expect-error
43+
defineConfig(() => ({})),
44+
defineConfig({}),
45+
)
46+
47+
export {}

packages/vite/src/node/config.ts

+2
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ export type UserConfigExport =
131131
export function defineConfig(config: UserConfig): UserConfig
132132
export function defineConfig(config: Promise<UserConfig>): Promise<UserConfig>
133133
export function defineConfig(config: UserConfigFnObject): UserConfigFnObject
134+
export function defineConfig(config: UserConfigFnPromise): UserConfigFnPromise
135+
export function defineConfig(config: UserConfigFn): UserConfigFn
134136
export function defineConfig(config: UserConfigExport): UserConfigExport
135137
export function defineConfig(config: UserConfigExport): UserConfigExport {
136138
return config

0 commit comments

Comments
 (0)