ZYinMD
ZYinMD

Reputation: 5159

Vitest in-source testing: Property 'vitest' does not exist on type 'ImportMeta'

I'm trying the in-source testing of vitest. Here is the example given by the doc:

if (import.meta.vitest) {
  const { it, expect } = import.meta.vitest;
  it('add', () => {
    expect(1 + 1).toBe(2);
  });
}

But I get the red squiggles Property 'vitest' does not exist on type 'ImportMeta' in VSCode. How can I fix it? enter image description here

Upvotes: 5

Views: 2964

Answers (1)

user446495
user446495

Reputation: 106

// tsconfig.json 
{"compilerOptions": {"types": ["vitest/importMeta"]}}

You can see the doc https://vitest.dev/guide/in-source.html#typescript

Upvotes: 9

Related Questions