Reputation: 143
As described in this answer and in the docs. I've added the reference types for Vitest at the top of my Vite config file.
/// <reference types="vitest" />
Why am I still getting the TypeScript warning 'test' does not exist in type 'UserConfigExport'
?
Upvotes: 11
Views: 3370
Reputation: 870
I defined my own type and extended it to UserConfig
.
...
import type { InlineConfig } from 'vitest';
import type { UserConfig } from 'vite';
interface VitestConfigExport extends UserConfig {
test: InlineConfig;
}
...
Then I casted the type of config
object to my custom interface -
export default defineConfig({
plugins: [solidPlugin()],
server: {
port: 3000,
},
test: {
environment: 'jsdom',
globals: true,
transformMode: {
web: [/\.[jt]sx?$/],
},
setupFiles: './setupVitest.ts',
},
build: {
target: 'esnext',
},
} as VitestConfigExport);
This also enabled intellisense for new test
property. Also, you don't need to define /// <reference types="vitest" />
.
Upvotes: 4
Reputation: 397
I have found a workaround for this problem - creating separate vitest.config.ts
file. As docs states:
Create
vitest.config.ts
, which will have the higher priority and will override the configuration fromvite.config.ts
Now you will have intellisense for test
option.
Example vitest.config.ts
file:
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
globals: true,
environment: 'jsdom',
coverage: {
provider: 'istanbul', // or 'c8',
all: true,
},
},
});
Upvotes: 5