-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type incompatibilities between mergeConfig
and defineConfig
when the latter is used with a function
#13950
Comments
This is expected. See #13135 (and the linked PR from it). You can call the config function before passing it to |
Thanks for your answer! I'm not sure I understand the workaround, to be honest. I have 2 issues:
Thanks again for your interest in this. Tell me if I'm not clear in what I'm asking! |
Let's reopen the issue to keep discussing this. I agree it would be good if And if that is the case, your code snippet for 2 seems good to me. You can cast the function for now after the first |
I've opened the pull request: #13958 |
Thanks! There is no automatic process to port things to Vitest, but you could first wait until #13958 is cleared. |
Would be nice to update the documentation with the latest info. I'm glad I found this issue, otherwise I wouldn't have figured out that I could use this pattern: import { mergeConfig, defineConfig } from 'vite';
import viteConfig from './vite.config';
export default defineConfig((env) => mergeConfig(
viteConfig(env),
defineConfig({
test: {
// vitest config
},
}),
)); |
@Anoesj would you like to send a PR to the Vitest repo to do that? That is a good contribution for the project |
@patak-dev I just created this pull request to add it to vite's documentation as well. Tell me if you don't think it's a good idea. |
Describe the bug
I am creating a config with
defineConfig
by providing a function. When I want to use this function inmergeConfig
, I get a TypeScript error:Argument of type 'UserConfigExport' is not assignable to parameter of type 'UserConfig | Promise<UserConfig>'. Type 'UserConfigFnObject' is not assignable to type 'UserConfig | Promise<UserConfig>'.
Here's the code that's in the typescript playground added as a reproduction. The function in
defineConfig
is a dummy function here to showcase the issue. I know that here, I could get rid of the function but in my real repository, I need to access thecommand
informationThe issue is that
mergeConfig
does not accept functions (seeD extends Function ? never : D,
invite/packages/vite/src/node/utils.ts
Line 1066 in a48bf88
UserConfigExport
is not an acceptable type for it.Is there something I'm doing wrong or is
defineConfig
not defined as it should be?Reproduction
https://www.typescriptlang.org/play#code/JYWwDg9gTgLgBAbzgEwKYDNgDtUGEJaYDmANHCKlEXgcXAL5zpQQhwDkAbsDKuwNwAoQQHoRcACIRUAZzhYI8AO7QA1nCUALVFjgBXGdiJwAhkz1YAxjGAE4YE1BMVeUQZYIz4HwsGMBeFAxsGl8iAApwgEo4fwA+OHCEQThU+wAbPSJsGQAuOABtAF0SQXooqKE0uEEKKlDicJS4H2JS1LRMHHwwpObUnU4ABShggA989iGAVQAhABkASVwAfXZ2hijSyuExOAB1NTktHXlFfUMsYzN0C2tbXQcnF0p3T29aPwAmWKCuhr8fWqYEy2SweUKJTKO1qlGoPUazVa3w2nRCCMByWqgxG40mMwWyzWG3K234QA
Steps to reproduce
No response
System Info
Used Package Manager
yarn
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: