vitest icon indicating copy to clipboard operation
vitest copied to clipboard

TS: Object literals can specify only known properties, and "test" is not in type "UserConfig"

Open cwandev opened this issue 3 years ago • 3 comments
trafficstars

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

cwandev avatar Aug 18 '22 06:08 cwandev

You might have different versions of Vite installed, and Vitest extends it's own Vite config type.

sheremet-va avatar Aug 18 '22 06:08 sheremet-va

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!

cwandev avatar Aug 18 '22 07:08 cwandev

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])

kevinvalk avatar Sep 05 '22 19:09 kevinvalk

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

dominikbulaj avatar Oct 03 '22 12:10 dominikbulaj

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.

sheremet-va avatar Oct 05 '22 13:10 sheremet-va

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.

I see, Thanks!

cwandev avatar Oct 07 '22 13:10 cwandev