vitest
vitest copied to clipboard
TS: Object literals can specify only known properties, and "test" is not in type "UserConfig"
Describe the bug
This is a type error, please tell me the correct solution.
Reproduction
/// <reference types="vitest" />
import type { ConfigEnv, UserConfig } from 'vite'
export default ({ command, mode }: ConfigEnv): UserConfig => {
return {
test: {},
}
}
System Info
mac os
Used Package Manager
yarn
Validations
- [x] Follow our Code of Conduct
- [x] Read the Contributing Guidelines.
- [x] Read the docs.
- [x] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [x] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [x] The provided reproduction is a minimal reproducible example of the bug.
You might have different versions of Vite installed, and Vitest extends it's own Vite config type.
You might have different versions of Vite installed, and Vitest extends it's own Vite config type.
Thank you for your reply, but I have checked and they are all the latest versions.
vite: 3.0.8 vitest: 0.22.0
It's really confusing!
Exact same problem here:
yarn list v1.22.19
├─ @vitejs/[email protected]
├─ @vitest/[email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
└─ [email protected]
└─ [email protected]
One of our devs was so smart to cast the defineConfig({} as Parameters<typeof defineConfig>[0])
Guys, I found solution. We need to import defineConfig from vitest
In my case, just changing import did the trick (I use vite.config.ts)
- import { defineConfig } from 'vite'
+ import { defineConfig } from 'vitest/config';
export default defineConfig({
// ...
test: {
globals: true,
environment: 'jsdom',
setupFiles: './tests/setup.ts',
},
})
Now TS error is gone. Hope it helps
So, this happens when you have several Vite versions installed. Check your lockfile and resolve the inconsistency. You can also bypass this by using defineConfig from vitest/config. Closing issue since this is not Vitest problem.
So, this happens when you have several Vite versions installed. Check your lockfile and resolve the inconsistency. You can also bypass this by using
defineConfigfromvitest/config. Closing issue since this is not Vitest problem.
I see, Thanks!