-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(types): add more overload to
defineConfig
(#18299)
- Loading branch information
1 parent
466f94a
commit 94e34cf
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* eslint-disable @typescript-eslint/ban-ts-comment */ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import type { Equal, ExpectTrue } from '@type-challenges/utils' | ||
import { | ||
type UserConfig, | ||
type UserConfigExport, | ||
type UserConfigFn, | ||
type UserConfigFnObject, | ||
type UserConfigFnPromise, | ||
defineConfig, | ||
} from '../config' | ||
import { mergeConfig } from '../publicUtils' | ||
|
||
const configObjectDefined = defineConfig({}) | ||
const configObjectPromiseDefined = defineConfig(Promise.resolve({})) | ||
const configFnObjectDefined = defineConfig(() => ({})) | ||
const configFnPromiseDefined = defineConfig(async () => ({})) | ||
const configFnDefined = defineConfig(() => | ||
// TypeScript requires both non-promise config and | ||
// promise config to have at least one property | ||
Math.random() > 0.5 ? { base: '' } : Promise.resolve({ base: '/' }), | ||
) | ||
const configExportDefined = defineConfig({} as UserConfigExport) | ||
|
||
export type cases1 = [ | ||
ExpectTrue<Equal<typeof configObjectDefined, UserConfig>>, | ||
ExpectTrue<Equal<typeof configObjectPromiseDefined, Promise<UserConfig>>>, | ||
ExpectTrue<Equal<typeof configFnObjectDefined, UserConfigFnObject>>, | ||
ExpectTrue<Equal<typeof configFnPromiseDefined, UserConfigFnPromise>>, | ||
ExpectTrue<Equal<typeof configFnDefined, UserConfigFn>>, | ||
ExpectTrue<Equal<typeof configExportDefined, UserConfigExport>>, | ||
] | ||
|
||
defineConfig({ | ||
base: '', | ||
// @ts-expect-error | ||
unknownProperty: 1, | ||
}) | ||
|
||
mergeConfig(defineConfig({}), defineConfig({})) | ||
mergeConfig( | ||
// @ts-expect-error | ||
defineConfig(() => ({})), | ||
defineConfig({}), | ||
) | ||
|
||
export {} |
This file contains 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