···7272 })
7373 ```
74747575+::: warning
7676+You cannot use this syntax, when using Vitest as [type checker](/guide/testing-types).
7777+:::
7878+7579### test.runIf
76807781- **Type:** `(condition: any) => Test`
···8892 // this test only runs in development
8993 })
9094 ```
9595+9696+::: warning
9797+You cannot use this syntax, when using Vitest as [type checker](/guide/testing-types).
9898+:::
919992100### test.only
93101···152160 })
153161 ```
154162163163+::: warning
164164+You cannot use this syntax, when using Vitest as [type checker](/guide/testing-types).
165165+:::
166166+155167### test.todo
156168157169- **Type:** `(name: string) => void`
···179191 })
180192 ```
181193194194+::: warning
195195+You cannot use this syntax, when using Vitest as [type checker](/guide/testing-types).
196196+:::
197197+182198### test.each
183199- **Type:** `(cases: ReadonlyArray<T>) => void`
184200- **Alias:** `it.each`
···210226 // ✓ add(2, 1) -> 3
211227 ```
212228229229+ You can also access object properties with `$` prefix, if you are using objects as arguments:
230230+231231+ ```ts
232232+ test.each([
233233+ { a: 1, b: 1, expected: 2 },
234234+ { a: 1, b: 2, expected: 3 },
235235+ { a: 2, b: 1, expected: 3 },
236236+ ])('add($a, $b) -> $expected', ({ a, b, expected }) => {
237237+ expect(a + b).toBe(expected)
238238+ })
239239+240240+ // this will return
241241+ // ✓ add(1, 1) -> 2
242242+ // ✓ add(1, 2) -> 3
243243+ // ✓ add(2, 1) -> 3
244244+ ```
245245+213246 If you want to have access to `TestContext`, use `describe.each` with a single test.
247247+248248+::: warning
249249+You cannot use this syntax, when using Vitest as [type checker](/guide/testing-types).
250250+:::
214251215252## bench
216253···472509 describe.todo.concurrent(/* ... */) // or describe.concurrent.todo(/* ... */)
473510 ```
474511512512+::: warning
513513+You cannot use this syntax, when using Vitest as [type checker](/guide/testing-types).
514514+:::
515515+475516### describe.shuffle
476517477518- **Type:** `(name: string, fn: TestFunction, options?: number | TestOptions) => void`
···488529 ```
489530490531`.skip`, `.only`, and `.todo` works with random suites.
532532+533533+::: warning
534534+You cannot use this syntax, when using Vitest as [type checker](/guide/testing-types).
535535+:::
491536492537### describe.todo
493538···526571 })
527572 ```
528573574574+::: warning
575575+You cannot use this syntax, when using Vitest as [type checker](/guide/testing-types).
576576+:::
577577+529578## expect
530579531580- **Type:** `ExpectStatic & (actual: any) => Assertions`
···546595 Technically this example doesn't use [`test`](#test) function, so in the console you will see Nodejs error instead of Vitest output. To learn more about `test`, please read [next chapter](#test).
547596548597 Also, `expect` can be used statically to access matchers functions, described later, and more.
598598+599599+::: warning
600600+`expect` has no effect on testing types, if expression doesn't have a type error. If you want to use Vitest as [type checker](/guide/testing-types), use [`expectTypeOf`](#expecttypeof) or [`assertType`](#asserttype).
601601+:::
549602550603### not
551604···17761829 If you want to know more, checkout [guide on extending matchers](/guide/extending-matchers).
17771830 :::
1778183118321832+## expectTypeOf
18331833+18341834+- **Type:** `<T>(a: unknown) => ExpectTypeOf`
18351835+18361836+### not
18371837+18381838+ - **Type:** `ExpectTypeOf`
18391839+18401840+ You can negate all assertions, using `.not` property.
18411841+18421842+### toEqualTypeOf
18431843+18441844+ - **Type:** `<T>(expected: T) => void`
18451845+18461846+ This matcher will check, if types are fully equal to each other. This matcher will not fail, if two objects have different values, but the same type, but will fail, if object is missing a property.
18471847+18481848+ ```ts
18491849+ import { expectTypeOf } from 'vitest'
18501850+18511851+ expectTypeOf({ a: 1 }).toEqualTypeOf<{ a: number }>()
18521852+ expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 1 })
18531853+ expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 2 })
18541854+ expectTypeOf({ a: 1, b: 1 }).not.toEqualTypeOf<{ a: number }>()
18551855+ ```
18561856+18571857+### toMatchTypeOf
18581858+18591859+ - **Type:** `<T>(expected: T) => void`
18601860+18611861+ This matcher checks if expect type extends provided type. It is different from `toEqual` and is more similar to expect's `toMatch`. With this matcher you can check, if an object "matches" a type.
18621862+18631863+ ```ts
18641864+ import { expectTypeOf } from 'vitest'
18651865+18661866+ expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf({ a: 1 })
18671867+ expectTypeOf<number>().toMatchTypeOf<string | number>()
18681868+ expectTypeOf<string | number>().not.toMatchTypeOf<number>()
18691869+ ```
18701870+18711871+### extract
18721872+18731873+ - **Type:** `ExpectTypeOf<ExtractedUnion>`
18741874+18751875+ You can use `.extract` to narrow down types for further testing.
18761876+18771877+ ```ts
18781878+ import { expectTypeOf } from 'vitest'
18791879+18801880+ type ResponsiveProp<T> = T | T[] | { xs?: T; sm?: T; md?: T }
18811881+ const getResponsiveProp = <T>(_props: T): ResponsiveProp<T> => ({})
18821882+ interface CSSProperties { margin?: string; padding?: string }
18831883+18841884+ const cssProperties: CSSProperties = { margin: '1px', padding: '2px' }
18851885+18861886+ expectTypeOf(getResponsiveProp(cssProperties))
18871887+ .extract<{ xs?: any }>() // extracts the last type from a union
18881888+ .toEqualTypeOf<{ xs?: CSSProperties; sm?: CSSProperties; md?: CSSProperties }>()
18891889+18901890+ expectTypeOf(getResponsiveProp(cssProperties))
18911891+ .extract<unknown[]>() // extracts an array from a union
18921892+ .toEqualTypeOf<CSSProperties[]>()
18931893+ ```
18941894+18951895+ ::: warning
18961896+ If no type is found in the union, `.extract` will return `never`.
18971897+ :::
18981898+18991899+### exclude
19001900+19011901+ - **Type:** `ExpectTypeOf<NonExcludedUnion>`
19021902+19031903+ You can use `.exclude` to remove types from a union for further testing.
19041904+19051905+ ```ts
19061906+ import { expectTypeOf } from 'vitest'
19071907+19081908+ type ResponsiveProp<T> = T | T[] | { xs?: T; sm?: T; md?: T }
19091909+ const getResponsiveProp = <T>(_props: T): ResponsiveProp<T> => ({})
19101910+ interface CSSProperties { margin?: string; padding?: string }
19111911+19121912+ const cssProperties: CSSProperties = { margin: '1px', padding: '2px' }
19131913+19141914+ expectTypeOf(getResponsiveProp(cssProperties))
19151915+ .exclude<unknown[]>()
19161916+ .exclude<{ xs?: unknown }>() // or just .exclude<unknown[] | { xs?: unknown }>()
19171917+ .toEqualTypeOf<CSSProperties>()
19181918+ ```
19191919+19201920+ ::: warning
19211921+ If no type is found in the union, `.exclude` will return `never`.
19221922+ :::
19231923+19241924+### returns
19251925+19261926+ - **Type:** `ExpectTypeOf<ReturnValue>`
19271927+19281928+ You can use `.returns` to extract return value of a function type.
19291929+19301930+ ```ts
19311931+ import { expectTypeOf } from 'vitest'
19321932+19331933+ expectTypeOf(() => {}).returns.toBeVoid()
19341934+ expectTypeOf((a: number) => [a, a]).returns.toEqualTypeOf([1, 2])
19351935+ ```
19361936+19371937+ ::: warning
19381938+ If used on a non-function type, it will return `never`, so you won't be able to chain it with other matchers.
19391939+ :::
19401940+19411941+### parameters
19421942+19431943+ - **Type:** `ExpectTypeOf<Parameters>`
19441944+19451945+ You can extract function arguments with `.parameters` to perform assertions on its value. Parameters are returned as an array.
19461946+19471947+ ```ts
19481948+ import { expectTypeOf } from 'vitest'
19491949+19501950+ type NoParam = () => void
19511951+ type HasParam = (s: string) => void
19521952+19531953+ expectTypeOf<NoParam>().parameters.toEqualTypeOf<[]>()
19541954+ expectTypeOf<HasParam>().parameters.toEqualTypeOf<[string]>()
19551955+ ```
19561956+19571957+ ::: warning
19581958+ If used on a non-function type, it will return `never`, so you won't be able to chain it with other matchers.
19591959+ :::
19601960+19611961+ ::: tip
19621962+ You can also use [`.toBeCallableWith`](#tobecallablewith) matcher as a more expressive assertion.
19631963+ :::
19641964+19651965+### parameter
19661966+19671967+ - **Type:** `(nth: number) => ExpectTypeOf`
19681968+19691969+ You can extract a certain function argument with `.parameter(number)` call to perform other assertions on it.
19701970+19711971+ ```ts
19721972+ import { expectTypeOf } from 'vitest'
19731973+19741974+ const foo = (a: number, b: string) => [a, b]
19751975+19761976+ expectTypeOf(foo).parameter(0).toBeNumber()
19771977+ expectTypeOf(foo).parameter(1).toBeString()
19781978+ ```
19791979+19801980+ ::: warning
19811981+ If used on a non-function type, it will return `never`, so you won't be able to chain it with other matchers.
19821982+ :::
19831983+19841984+### constructorParameters
19851985+19861986+ - **Type:** `ExpectTypeOf<ConstructorParameters>`
19871987+19881988+ You can extract constructor parameters as an array of values and perform assertions on them with this method.
19891989+19901990+ ```ts
19911991+ import { expectTypeOf } from 'vitest'
19921992+19931993+ expectTypeOf(Date).constructorParameters.toEqualTypeOf<[] | [string | number | Date]>()
19941994+ ```
19951995+19961996+ ::: warning
19971997+ If used on a non-function type, it will return `never`, so you won't be able to chain it with other matchers.
19981998+ :::
19991999+20002000+ ::: tip
20012001+ You can also use [`.toBeConstructibleWith`](#tobeconstructiblewith) matcher as a more expressive assertion.
20022002+ :::
20032003+20042004+### instance
20052005+20062006+ - **Type:** `ExpectTypeOf<ConstructableInstance>`
20072007+20082008+ This property gives access to matchers that can be performed on an instance of the provided class.
20092009+20102010+ ```ts
20112011+ import { expectTypeOf } from 'vitest'
20122012+20132013+ expectTypeOf(Date).instance.toHaveProperty('toISOString')
20142014+ ```
20152015+20162016+ ::: warning
20172017+ If used on a non-function type, it will return `never`, so you won't be able to chain it with other matchers.
20182018+ :::
20192019+20202020+### items
20212021+20222022+ - **Type:** `ExpectTypeOf<T>`
20232023+20242024+ You can get array item type with `.items` to perform further assertions.
20252025+20262026+ ```ts
20272027+ import { expectTypeOf } from 'vitest'
20282028+20292029+ expectTypeOf([1, 2, 3]).items.toEqualTypeOf<number>()
20302030+ expectTypeOf([1, 2, 3]).items.not.toEqualTypeOf<string>()
20312031+ ```
20322032+20332033+### resolves
20342034+20352035+ - **Type:** `ExpectTypeOf<ResolvedPromise>`
20362036+20372037+ This matcher extracts resolved value of a `Promise`, so you can perform other assertions on it.
20382038+20392039+ ```ts
20402040+ import { expectTypeOf } from 'vitest'
20412041+20422042+ const asyncFunc = async () => 123
20432043+20442044+ expectTypeOf(asyncFunc).returns.resolves.toBeNumber()
20452045+ expectTypeOf(Promise.resolve('string')).resolves.toBeString()
20462046+ ```
20472047+20482048+ ::: warning
20492049+ If used on a non-promise type, it will return `never`, so you won't be able to chain it with other matchers.
20502050+ :::
20512051+20522052+### guards
20532053+20542054+ - **Type:** `ExpectTypeOf<Guard>`
20552055+20562056+ This matcher extracts guard value (e.g., `v is number`), so you can perform assertions on it.
20572057+20582058+ ```ts
20592059+ import { expectTypeOf } from 'vitest'
20602060+20612061+ const isString = (v: any): v is string => typeof v === 'string'
20622062+ expectTypeOf(isString).guards.toBeString()
20632063+ ```
20642064+20652065+ ::: warning
20662066+ Returns `never`, if the value is not a guard function, so you won't be able to chain it with other matchers.
20672067+ :::
20682068+20692069+### asserts
20702070+20712071+ - **Type:** `ExpectTypeOf<Assert>`
20722072+20732073+ This matcher extracts assert value (e.g., `assert v is number`), so you can perform assertions on it.
20742074+20752075+ ```ts
20762076+ import { expectTypeOf } from 'vitest'
20772077+20782078+ const assertNumber = (v: any): asserts v is number => {
20792079+ if (typeof v !== 'number')
20802080+ throw new TypeError('Nope !')
20812081+ }
20822082+20832083+ expectTypeOf(assertNumber).asserts.toBeNumber()
20842084+ ```
20852085+20862086+ ::: warning
20872087+ Returns `never`, if the value is not an assert function, so you won't be able to chain it with other matchers.
20882088+ :::
20892089+20902090+### toBeAny
20912091+20922092+ - **Type:** `() => void`
20932093+20942094+ With this matcher you can check, if provided type is `any` type. If the type is too specific, the test will fail.
20952095+20962096+ ```ts
20972097+ import { expectTypeOf } from 'vitest'
20982098+20992099+ expectTypeOf<any>().toBeAny()
21002100+ expectTypeOf({} as any).toBeAny()
21012101+ expectTypeOf('string').not.toBeAny()
21022102+ ```
21032103+21042104+### toBeUnknown
21052105+21062106+ - **Type:** `() => void`
21072107+21082108+ This matcher checks, if provided type is `unknown` type.
21092109+21102110+ ```ts
21112111+ import { expectTypeOf } from 'vitest'
21122112+21132113+ expectTypeOf().toBeUnknown()
21142114+ expectTypeOf({} as unknown).toBeUnknown()
21152115+ expectTypeOf('string').not.toBeUnknown()
21162116+ ```
21172117+21182118+### toBeNever
21192119+21202120+ - **Type:** `() => void`
21212121+21222122+ This matcher checks, if provided type is a `never` type.
21232123+21242124+ ```ts
21252125+ import { expectTypeOf } from 'vitest'
21262126+21272127+ expectTypeOf<never>().toBeNever()
21282128+ expectTypeOf((): never => {}).returns.toBeNever()
21292129+ ```
21302130+21312131+### toBeFunction
21322132+21332133+ - **Type:** `() => void`
21342134+21352135+ This matcher checks, if provided type is a `functon`.
21362136+21372137+ ```ts
21382138+ import { expectTypeOf } from 'vitest'
21392139+21402140+ expectTypeOf(42).not.toBeFunction()
21412141+ expectTypeOf((): never => {}).toBeFunction()
21422142+ ```
21432143+21442144+### toBeObject
21452145+21462146+ - **Type:** `() => void`
21472147+21482148+ This matcher checks, if provided type is an `object`.
21492149+21502150+ ```ts
21512151+ import { expectTypeOf } from 'vitest'
21522152+21532153+ expectTypeOf(42).not.toBeObject()
21542154+ expectTypeOf({}).toBeObject()
21552155+ ```
21562156+21572157+### toBeArray
21582158+21592159+ - **Type:** `() => void`
21602160+21612161+ This matcher checks, if provided type is `Array<T>`.
21622162+21632163+ ```ts
21642164+ import { expectTypeOf } from 'vitest'
21652165+21662166+ expectTypeOf(42).not.toBeArray()
21672167+ expectTypeOf([]).toBeArray()
21682168+ expectTypeOf([1, 2]).toBeArray()
21692169+ expectTypeOf([{}, 42]).toBeArray()
21702170+ ```
21712171+21722172+### toBeString
21732173+21742174+ - **Type:** `() => void`
21752175+21762176+ This matcher checks, if provided type is a `string`.
21772177+21782178+ ```ts
21792179+ import { expectTypeOf } from 'vitest'
21802180+21812181+ expectTypeOf(42).not.toBeArray()
21822182+ expectTypeOf([]).toBeArray()
21832183+ expectTypeOf([1, 2]).toBeArray()
21842184+ expectTypeOf<number[]>().toBeArray()
21852185+ ```
21862186+21872187+### toBeBoolean
21882188+21892189+ - **Type:** `() => void`
21902190+21912191+ This matcher checks, if provided type is `boolean`.
21922192+21932193+ ```ts
21942194+ import { expectTypeOf } from 'vitest'
21952195+21962196+ expectTypeOf(42).not.toBeBoolean()
21972197+ expectTypeOf(true).toBeBoolean()
21982198+ expectTypeOf<boolean>().toBeBoolean()
21992199+ ```
22002200+22012201+### toBeVoid
22022202+22032203+ - **Type:** `() => void`
22042204+22052205+ This matcher checks, if provided type is `void`.
22062206+22072207+ ```ts
22082208+ import { expectTypeOf } from 'vitest'
22092209+22102210+ expectTypeOf(() => {}).returns.toBeVoid()
22112211+ expectTypeOf<void>().toBeVoid()
22122212+ ```
22132213+22142214+### toBeSymbol
22152215+22162216+ - **Type:** `() => void`
22172217+22182218+ This matcher checks, if provided type is a `symbol`.
22192219+22202220+ ```ts
22212221+ import { expectTypeOf } from 'vitest'
22222222+22232223+ expectTypeOf(Symbol(1)).toBeSymbol()
22242224+ expectTypeOf<symbol>().toBeSymbol()
22252225+ ```
22262226+22272227+### toBeNull
22282228+22292229+ - **Type:** `() => void`
22302230+22312231+ This matcher checks, if provided type is `null`.
22322232+22332233+ ```ts
22342234+ import { expectTypeOf } from 'vitest'
22352235+22362236+ expectTypeOf(null).toBeNull()
22372237+ expectTypeOf<null>().toBeNull()
22382238+ expectTypeOf(undefined).not.toBeNull()
22392239+ ```
22402240+22412241+### toBeUndefined
22422242+22432243+ - **Type:** `() => void`
22442244+22452245+ This matcher checks, if provided type is `undefined`.
22462246+22472247+ ```ts
22482248+ import { expectTypeOf } from 'vitest'
22492249+22502250+ expectTypeOf(undefined).toBeUndefined()
22512251+ expectTypeOf<undefined>().toBeUndefined()
22522252+ expectTypeOf(null).not.toBeUndefined()
22532253+ ```
22542254+22552255+### toBeNullable
22562256+22572257+ - **Type:** `() => void`
22582258+22592259+ This matcher checks, if you can use `null` or `undefined` with provided type.
22602260+22612261+ ```ts
22622262+ import { expectTypeOf } from 'vitest'
22632263+22642264+ expectTypeOf<1 | undefined>().toBeNullable()
22652265+ expectTypeOf<1 | null>().toBeNullable()
22662266+ expectTypeOf<1 | undefined | null>().toBeNullable()
22672267+ ```
22682268+22692269+### toBeCallableWith
22702270+22712271+ - **Type:** `() => void`
22722272+22732273+ This matcher ensures you can call provided function with a set of parameters.
22742274+22752275+ ```ts
22762276+ import { expectTypeOf } from 'vitest'
22772277+22782278+ type NoParam = () => void
22792279+ type HasParam = (s: string) => void
22802280+22812281+ expectTypeOf<NoParam>().toBeCallableWith()
22822282+ expectTypeOf<HasParam>().toBeCallableWith('some string')
22832283+ ```
22842284+22852285+ ::: warning
22862286+ If used on a non-function type, it will return `never`, so you won't be able to chain it with other matchers.
22872287+ :::
22882288+22892289+### toBeConstructibleWith
22902290+22912291+ - **Type:** `() => void`
22922292+22932293+ This matcher ensures you can create a new instance with a set of constructor parameters.
22942294+22952295+ ```ts
22962296+ import { expectTypeOf } from 'vitest'
22972297+22982298+ expectTypeOf(Date).toBeConstructibleWith(new Date())
22992299+ expectTypeOf(Date).toBeConstructibleWith('01-01-2000')
23002300+ ```
23012301+23022302+ ::: warning
23032303+ If used on a non-function type, it will return `never`, so you won't be able to chain it with other matchers.
23042304+ :::
23052305+23062306+### toHaveProperty
23072307+23082308+ - **Type:** `<K extends keyof T>(property: K) => ExpectTypeOf<T[K>`
23092309+23102310+ This matcher checks if a property exists on provided object. If it exists, it also returns the same set of matchers for the type of this property, so you can chain assertions one after another.
23112311+23122312+ ```ts
23132313+ import { expectTypeOf } from 'vitest'
23142314+23152315+ const obj = { a: 1, b: '' }
23162316+23172317+ expectTypeOf(obj).toHaveProperty('a')
23182318+ expectTypeOf(obj).not.toHaveProperty('c')
23192319+23202320+ expectTypeOf(obj).toHaveProperty('a').toBeNumber()
23212321+ expectTypeOf(obj).toHaveProperty('b').toBeString()
23222322+ expectTypeOf(obj).toHaveProperty('a').not.toBeString()
23232323+ ```
23242324+23252325+## assertType
23262326+23272327+ - **Type:** `<T>(value: T): void`
23282328+23292329+ You can use this function as an alternative for `expectTypeOf` to easily assert that argument type is equal to provided generic.
23302330+23312331+ ```ts
23322332+ import { assertType } from 'vitest'
23332333+23342334+ function concat(a: string, b: string): string
23352335+ function concat(a: number, b: number): number
23362336+ function concat(a: string | number, b: string | number): string | number
23372337+23382338+ assertType<string>(concat('a', 'b'))
23392339+ assertType<number>(concat(1, 2))
23402340+ // @ts-expect-error wrong types
23412341+ assertType(concat('a', 2))
23422342+ ```
23432343+17792344## Setup and Teardown
1780234517811781-These functions allow you to hook into the life cycle of tests to avoid repeating setup and teardown code. They apply to the current context: the file if they are used at the top-level or the current suite if they are inside a `describe` block.
23462346+These functions allow you to hook into the life cycle of tests to avoid repeating setup and teardown code. They apply to the current context: the file if they are used at the top-level or the current suite if they are inside a `describe` block. These hooks are not called, when you are running Vitest as a type checker.
1782234717832348### beforeEach
17842349···1970253519712536- **Type**: `(path: string, factory?: () => unknown) => void`
1972253719731973- Makes all `imports` to passed module to be mocked. Inside a path you _can_ use configured Vite aliases.
25382538+ Makes all `imports` to passed module to be mocked. Inside a path you _can_ use configured Vite aliases. The call to `vi.mock` is hoisted, so it doesn't matter where you call it. It will always be executed before all imports.
1974253919751975- - If `factory` is defined, will return its result. Factory function can be asynchronous. You may call [`vi.importActual`](#vi-importactual) inside to get the original module. The call to `vi.mock` is hoisted to the top of the file, so you don't have access to variables declared in the global file scope!
25402540+ - If `factory` is defined, will return its result. Factory function can be asynchronous. You may call [`vi.importActual`](#vi-importactual) inside to get the original module. Since the call to `vi.mock` is hoisted, you don't have access to variables declared in the global file scope!
19762541 - If mocking a module with a default export, you'll need to provide a `default` key within the returned factory function object. This is an ES modules specific caveat, therefore `jest` documentation may differ as `jest` uses commonJS modules. *Example:*
1977254219782543 ```ts
+55
docs/config/index.md
···849849- **Default**: `Date.now()`
850850851851Sets the randomization seed, if tests are running in random order.
852852+853853+### typecheck
854854+855855+Options for configuring [typechecking](/guide/testing-types) test environment.
856856+857857+#### typecheck.checker
858858+859859+- **Type**: `'tsc' | 'vue-tsc' | string`
860860+- **Default**: `tsc`
861861+862862+What tools to use for type checking. Vitest will spawn a process with certain parameters for easier parsing, depending on the type. Checker should implement the same output format as `tsc`.
863863+864864+You need to have a package installed to use typecheker:
865865+866866+- `tsc` requires `typescript` package
867867+- `vue-tsc` requires `vue-tsc` package
868868+869869+You can also pass down a path to custom binary or command name that produces the same output as `tsc --noEmit --pretty false`.
870870+871871+#### typecheck.include
872872+873873+- **Type**: `string[]`
874874+- **Default**: `['**/*.{test,spec}-d.{ts,js}']`
875875+876876+Glob pattern for files that should be treated as test files
877877+878878+#### typecheck.exclude
879879+880880+- **Type**: `string[]`
881881+- **Default**: `['**/node_modules/**', '**/dist/**', '**/cypress/**', '**/.{idea,git,cache,output,temp}/**']`
882882+883883+Glob pattern for files that should not be treated as test files
884884+885885+#### typecheck.allowJs
886886+887887+- **Type**: `boolean`
888888+- **Default**: `false`
889889+890890+Check JS files that have `@ts-check` comment. If you have it enabled in tsconfig, this will not overwrite it.
891891+892892+#### typecheck.ignoreSourceErrors
893893+894894+- **Type**: `boolean`
895895+- **Default**: `false`
896896+897897+Do not fail, if Vitest found errors outside the test files. This will not show you non-test errors at all.
898898+899899+By default, if Vitest finds source error, it will fail test suite.
900900+901901+#### typecheck.tsconfig
902902+903903+- **Type**: `string`
904904+- **Default**: _tries to find closest tsconfig.json_
905905+906906+Path to custom tsconfig, relative to the project root.
+17
docs/guide/features.md
···200200 })
201201})
202202```
203203+204204+## Type Testing <sup><code>experimental</code></sup>
205205+206206+Since Vitest 0.25.0 you can [write tests](/guide/testing-types) to catch type regressions. Vitest comes with [`expect-type`](https://github.com/mmkal/expect-type) package to provide you with a similar and easy to understand API.
207207+208208+```ts
209209+import { assertType, expectTypeOf } from 'vitest'
210210+import { mount } from './mount.js'
211211+212212+test('my types work properly', () => {
213213+ expectTypeOf(mount).toBeFunction()
214214+ expectTypeOf(mount).parameter(0).toMatchTypeOf<{ name: string }>()
215215+216216+ // @ts-expect-error name is a string
217217+ assertType(mount({ name: 42 }))
218218+})
219219+```
+92
docs/guide/testing-types.md
···11+---
22+title: Testing Types | Guide
33+---
44+55+# Testing Types
66+77+Vitest allows you to write tests for your types, using `expectTypeOf` or `assertType` syntaxes. By default all tests inside `*.test-d.ts` files are considered type tests, but you can change it with [`typecheck.include`](/config/#typecheck-include) config option.
88+99+Under the hood Vitest calls `tsc` or `vue-tsc`, depending on your config, and parses results. Vitest will also print out type errors in your source code, if it finds any. You can disable it with [`typecheck.ignoreSourceErrors`](/config/#typecheck-ignoresourceerrors) config option.
1010+1111+Keep in mind that Vitest doesn't run or compile these files, they are only statically analyzed by the compiler, and because of that you cannot use any dynamic statements. Meaning, you cannot use dynamic test names, and `test.each`, `test.runIf`, `test.skipIf`, `test.each`, `test.concurrent` APIs. But you can use other APIs, like `test`, `describe`, `.only`, `.skip` and `.todo`.
1212+1313+Using CLI flags, like `--allowOnly` and `-t` are also supported for type checking.
1414+1515+```ts
1616+import { assertType, expectTypeOf } from 'vitest'
1717+import { mount } from './mount.js'
1818+1919+test('my types work properly', () => {
2020+ expectTypeOf(mount).toBeFunction()
2121+ expectTypeOf(mount).parameter(0).toMatchTypeOf<{ name: string }>()
2222+2323+ // @ts-expect-error name is a string
2424+ assertType(mount({ name: 42 }))
2525+})
2626+```
2727+2828+Any type error triggered inside a test file will be treated as a test error, so you can use any type trick you want to test types of your project.
2929+3030+You can see a list of possible matchers in [API section](/api/#expecttypeof).
3131+3232+## Reading Errors
3333+3434+If you are using `expectTypeOf` API, you might notice hard to read errors or unexpected:
3535+3636+```ts
3737+expectTypeOf(1).toEqualTypeOf<string>()
3838+// ^^^^^^^^^^^^^^^^^^^^^^
3939+// index-c3943160.d.ts(90, 20): Arguments for the rest parameter 'MISMATCH' were not provided.
4040+```
4141+4242+This is due to how [`expect-type`](https://github.com/mmkal/expect-type) handles type errors.
4343+4444+Unfortunately, TypeScript doesn't provide type metadata without patching, so we cannot provide useful error messages at this point, but there are <a href="https://github.com/microsoft/TypeScript/pull/40468" tatger="_blank">works in TypeScript project</a> to fix this. If you want better messages, please, ask TypeScript team to have a look at mentioned PR.
4545+4646+If you find it hard working with `expectTypeOf` API and figuring out errors, you can always use more simple `assertType` API:
4747+4848+```ts
4949+const answer = 42
5050+5151+assertType<number>(answer)
5252+// @ts-expect-error answer is not a string
5353+assertType<string>(answer)
5454+```
5555+5656+::: tip
5757+When using `@ts-expect-error` syntax, you might want to make sure that you didn't make a typo. You can do that by including your type files in [`test.include`](/config/#include) config option, so Vitest will also actually *run* these tests and fail with `ReferenceError`.
5858+5959+This will pass, because it expects an error, but the word “answer” has a typo, so it's a false positive error:
6060+6161+```ts
6262+// @ts-expect-error answer is not a string
6363+assertType<string>(answr) //
6464+```
6565+:::
6666+6767+## Run typechecking
6868+6969+Add this command to your `scripts` section in `package.json`:
7070+7171+```json
7272+{
7373+ "scripts": {
7474+ "typecheck": "vitest typecheck"
7575+ }
7676+}
7777+```
7878+7979+Now you can run typecheck:
8080+8181+```sh
8282+# npm
8383+npm run typecheck
8484+8585+# yarn
8686+yarn typecheck
8787+8888+# pnpm
8989+pnpm run typecheck
9090+```
9191+9292+Vitest uses `tsc --noEmit` or `vue-tsc --noEmit`, depending on your configuration, so you can remove these scripts from your pipeline.
+4-4
packages/ui/client/composables/summary.ts
···11import { hasFailedSnapshot } from '@vitest/ws-client'
22-import type { Benchmark, Task, Test } from 'vitest/src'
22+import type { Benchmark, Task, Test, TypeCheck } from 'vitest/src'
33import { files, testRunState } from '~/composables/client'
4455type Nullable<T> = T | null | undefined
···5252 return array
5353 return [array]
5454}
5555-function isAtomTest(s: Task): s is Test | Benchmark {
5656- return (s.type === 'test' || s.type === 'benchmark')
5555+function isAtomTest(s: Task): s is Test | Benchmark | TypeCheck {
5656+ return (s.type === 'test' || s.type === 'benchmark' || s.type === 'typecheck')
5757}
5858-function getTests(suite: Arrayable<Task>): (Test | Benchmark)[] {
5858+function getTests(suite: Arrayable<Task>): (Test | Benchmark | TypeCheck)[] {
5959 return toArray(suite).flatMap(s => isAtomTest(s) ? [s] : s.tasks.flatMap(c => isAtomTest(c) ? [c] : getTests(c)))
6060}
···197197198198---------------------------------------
199199200200-## acorn
201201-License: MIT
202202-By: Marijn Haverbeke, Ingvar Stepanyan, Adrian Heine
203203-Repository: https://github.com/acornjs/acorn.git
204204-205205-> MIT License
206206->
207207-> Copyright (C) 2012-2022 by various contributors (see AUTHORS)
208208->
209209-> Permission is hereby granted, free of charge, to any person obtaining a copy
210210-> of this software and associated documentation files (the "Software"), to deal
211211-> in the Software without restriction, including without limitation the rights
212212-> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
213213-> copies of the Software, and to permit persons to whom the Software is
214214-> furnished to do so, subject to the following conditions:
215215->
216216-> The above copyright notice and this permission notice shall be included in
217217-> all copies or substantial portions of the Software.
218218->
219219-> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
220220-> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
221221-> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
222222-> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
223223-> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
224224-> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
225225-> THE SOFTWARE.
226226-227227----------------------------------------
228228-229200## ansi-escapes
230201License: MIT
231202By: Sindre Sorhus
···603574604575---------------------------------------
605576577577+## expect-type
578578+License: Apache-2.0
579579+Repository: https://github.com/mmkal/expect-type.git
580580+581581+> Apache License
582582+> Version 2.0, January 2004
583583+> http://www.apache.org/licenses/
584584+>
585585+> TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
586586+>
587587+> 1. Definitions.
588588+>
589589+> "License" shall mean the terms and conditions for use, reproduction,
590590+> and distribution as defined by Sections 1 through 9 of this document.
591591+>
592592+> "Licensor" shall mean the copyright owner or entity authorized by
593593+> the copyright owner that is granting the License.
594594+>
595595+> "Legal Entity" shall mean the union of the acting entity and all
596596+> other entities that control, are controlled by, or are under common
597597+> control with that entity. For the purposes of this definition,
598598+> "control" means (i) the power, direct or indirect, to cause the
599599+> direction or management of such entity, whether by contract or
600600+> otherwise, or (ii) ownership of fifty percent (50%) or more of the
601601+> outstanding shares, or (iii) beneficial ownership of such entity.
602602+>
603603+> "You" (or "Your") shall mean an individual or Legal Entity
604604+> exercising permissions granted by this License.
605605+>
606606+> "Source" form shall mean the preferred form for making modifications,
607607+> including but not limited to software source code, documentation
608608+> source, and configuration files.
609609+>
610610+> "Object" form shall mean any form resulting from mechanical
611611+> transformation or translation of a Source form, including but
612612+> not limited to compiled object code, generated documentation,
613613+> and conversions to other media types.
614614+>
615615+> "Work" shall mean the work of authorship, whether in Source or
616616+> Object form, made available under the License, as indicated by a
617617+> copyright notice that is included in or attached to the work
618618+> (an example is provided in the Appendix below).
619619+>
620620+> "Derivative Works" shall mean any work, whether in Source or Object
621621+> form, that is based on (or derived from) the Work and for which the
622622+> editorial revisions, annotations, elaborations, or other modifications
623623+> represent, as a whole, an original work of authorship. For the purposes
624624+> of this License, Derivative Works shall not include works that remain
625625+> separable from, or merely link (or bind by name) to the interfaces of,
626626+> the Work and Derivative Works thereof.
627627+>
628628+> "Contribution" shall mean any work of authorship, including
629629+> the original version of the Work and any modifications or additions
630630+> to that Work or Derivative Works thereof, that is intentionally
631631+> submitted to Licensor for inclusion in the Work by the copyright owner
632632+> or by an individual or Legal Entity authorized to submit on behalf of
633633+> the copyright owner. For the purposes of this definition, "submitted"
634634+> means any form of electronic, verbal, or written communication sent
635635+> to the Licensor or its representatives, including but not limited to
636636+> communication on electronic mailing lists, source code control systems,
637637+> and issue tracking systems that are managed by, or on behalf of, the
638638+> Licensor for the purpose of discussing and improving the Work, but
639639+> excluding communication that is conspicuously marked or otherwise
640640+> designated in writing by the copyright owner as "Not a Contribution."
641641+>
642642+> "Contributor" shall mean Licensor and any individual or Legal Entity
643643+> on behalf of whom a Contribution has been received by Licensor and
644644+> subsequently incorporated within the Work.
645645+>
646646+> 2. Grant of Copyright License. Subject to the terms and conditions of
647647+> this License, each Contributor hereby grants to You a perpetual,
648648+> worldwide, non-exclusive, no-charge, royalty-free, irrevocable
649649+> copyright license to reproduce, prepare Derivative Works of,
650650+> publicly display, publicly perform, sublicense, and distribute the
651651+> Work and such Derivative Works in Source or Object form.
652652+>
653653+> 3. Grant of Patent License. Subject to the terms and conditions of
654654+> this License, each Contributor hereby grants to You a perpetual,
655655+> worldwide, non-exclusive, no-charge, royalty-free, irrevocable
656656+> (except as stated in this section) patent license to make, have made,
657657+> use, offer to sell, sell, import, and otherwise transfer the Work,
658658+> where such license applies only to those patent claims licensable
659659+> by such Contributor that are necessarily infringed by their
660660+> Contribution(s) alone or by combination of their Contribution(s)
661661+> with the Work to which such Contribution(s) was submitted. If You
662662+> institute patent litigation against any entity (including a
663663+> cross-claim or counterclaim in a lawsuit) alleging that the Work
664664+> or a Contribution incorporated within the Work constitutes direct
665665+> or contributory patent infringement, then any patent licenses
666666+> granted to You under this License for that Work shall terminate
667667+> as of the date such litigation is filed.
668668+>
669669+> 4. Redistribution. You may reproduce and distribute copies of the
670670+> Work or Derivative Works thereof in any medium, with or without
671671+> modifications, and in Source or Object form, provided that You
672672+> meet the following conditions:
673673+>
674674+> (a) You must give any other recipients of the Work or
675675+> Derivative Works a copy of this License; and
676676+>
677677+> (b) You must cause any modified files to carry prominent notices
678678+> stating that You changed the files; and
679679+>
680680+> (c) You must retain, in the Source form of any Derivative Works
681681+> that You distribute, all copyright, patent, trademark, and
682682+> attribution notices from the Source form of the Work,
683683+> excluding those notices that do not pertain to any part of
684684+> the Derivative Works; and
685685+>
686686+> (d) If the Work includes a "NOTICE" text file as part of its
687687+> distribution, then any Derivative Works that You distribute must
688688+> include a readable copy of the attribution notices contained
689689+> within such NOTICE file, excluding those notices that do not
690690+> pertain to any part of the Derivative Works, in at least one
691691+> of the following places: within a NOTICE text file distributed
692692+> as part of the Derivative Works; within the Source form or
693693+> documentation, if provided along with the Derivative Works; or,
694694+> within a display generated by the Derivative Works, if and
695695+> wherever such third-party notices normally appear. The contents
696696+> of the NOTICE file are for informational purposes only and
697697+> do not modify the License. You may add Your own attribution
698698+> notices within Derivative Works that You distribute, alongside
699699+> or as an addendum to the NOTICE text from the Work, provided
700700+> that such additional attribution notices cannot be construed
701701+> as modifying the License.
702702+>
703703+> You may add Your own copyright statement to Your modifications and
704704+> may provide additional or different license terms and conditions
705705+> for use, reproduction, or distribution of Your modifications, or
706706+> for any such Derivative Works as a whole, provided Your use,
707707+> reproduction, and distribution of the Work otherwise complies with
708708+> the conditions stated in this License.
709709+>
710710+> 5. Submission of Contributions. Unless You explicitly state otherwise,
711711+> any Contribution intentionally submitted for inclusion in the Work
712712+> by You to the Licensor shall be under the terms and conditions of
713713+> this License, without any additional terms or conditions.
714714+> Notwithstanding the above, nothing herein shall supersede or modify
715715+> the terms of any separate license agreement you may have executed
716716+> with Licensor regarding such Contributions.
717717+>
718718+> 6. Trademarks. This License does not grant permission to use the trade
719719+> names, trademarks, service marks, or product names of the Licensor,
720720+> except as required for reasonable and customary use in describing the
721721+> origin of the Work and reproducing the content of the NOTICE file.
722722+>
723723+> 7. Disclaimer of Warranty. Unless required by applicable law or
724724+> agreed to in writing, Licensor provides the Work (and each
725725+> Contributor provides its Contributions) on an "AS IS" BASIS,
726726+> WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
727727+> implied, including, without limitation, any warranties or conditions
728728+> of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
729729+> PARTICULAR PURPOSE. You are solely responsible for determining the
730730+> appropriateness of using or redistributing the Work and assume any
731731+> risks associated with Your exercise of permissions under this License.
732732+>
733733+> 8. Limitation of Liability. In no event and under no legal theory,
734734+> whether in tort (including negligence), contract, or otherwise,
735735+> unless required by applicable law (such as deliberate and grossly
736736+> negligent acts) or agreed to in writing, shall any Contributor be
737737+> liable to You for damages, including any direct, indirect, special,
738738+> incidental, or consequential damages of any character arising as a
739739+> result of this License or out of the use or inability to use the
740740+> Work (including but not limited to damages for loss of goodwill,
741741+> work stoppage, computer failure or malfunction, or any and all
742742+> other commercial damages or losses), even if such Contributor
743743+> has been advised of the possibility of such damages.
744744+>
745745+> 9. Accepting Warranty or Additional Liability. While redistributing
746746+> the Work or Derivative Works thereof, You may choose to offer,
747747+> and charge a fee for, acceptance of support, warranty, indemnity,
748748+> or other liability obligations and/or rights consistent with this
749749+> License. However, in accepting such obligations, You may act only
750750+> on Your own behalf and on Your sole responsibility, not on behalf
751751+> of any other Contributor, and only if You agree to indemnify,
752752+> defend, and hold each Contributor harmless for any liability
753753+> incurred by, or claims asserted against, such Contributor by reason
754754+> of your accepting any such warranty or additional liability.
755755+>
756756+> END OF TERMS AND CONDITIONS
757757+>
758758+> APPENDIX: How to apply the Apache License to your work.
759759+>
760760+> To apply the Apache License to your work, attach the following
761761+> boilerplate notice, with the fields enclosed by brackets "[]"
762762+> replaced with your own identifying information. (Don't include
763763+> the brackets!) The text should be enclosed in the appropriate
764764+> comment syntax for the file format. We also recommend that a
765765+> file or class name and description of purpose be included on the
766766+> same "printed page" as the copyright notice for easier
767767+> identification within third-party archives.
768768+>
769769+> Copyright [yyyy] [name of copyright owner]
770770+>
771771+> Licensed under the Apache License, Version 2.0 (the "License");
772772+> you may not use this file except in compliance with the License.
773773+> You may obtain a copy of the License at
774774+>
775775+> http://www.apache.org/licenses/LICENSE-2.0
776776+>
777777+> Unless required by applicable law or agreed to in writing, software
778778+> distributed under the License is distributed on an "AS IS" BASIS,
779779+> WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
780780+> See the License for the specific language governing permissions and
781781+> limitations under the License.
782782+783783+---------------------------------------
784784+606785## fast-glob
607786License: MIT
608787By: Denis Malinochkin
···736915> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
737916>
738917> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
918918+919919+---------------------------------------
920920+921921+## get-tsconfig
922922+License: MIT
923923+By: Hiroki Osame
924924+Repository: privatenumber/get-tsconfig
925925+926926+> MIT License
927927+>
928928+> Copyright (c) Hiroki Osame <hiroki.osame@gmail.com>
929929+>
930930+> Permission is hereby granted, free of charge, to any person obtaining a copy
931931+> of this software and associated documentation files (the "Software"), to deal
932932+> in the Software without restriction, including without limitation the rights
933933+> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
934934+> copies of the Software, and to permit persons to whom the Software is
935935+> furnished to do so, subject to the following conditions:
936936+>
937937+> The above copyright notice and this permission notice shall be included in all
938938+> copies or substantial portions of the Software.
939939+>
940940+> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
941941+> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
942942+> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
943943+> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
944944+> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
945945+> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
946946+> SOFTWARE.
739947740948---------------------------------------
741949···1286149412871495> MIT License
12881496>
12891289-> Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
14971497+> Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
12901498>
12911499> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12921500>
···11+export type RawErrsMap = Map<string, TscErrorInfo[]>
22+export interface TscErrorInfo {
33+ filePath: string
44+ errCode: number
55+ errMsg: string
66+ line: number
77+ column: number
88+}
99+export interface CollectLineNumbers {
1010+ target: number
1111+ next: number
1212+ prev?: number
1313+}
1414+export type CollectLines = {
1515+ [key in keyof CollectLineNumbers]: string
1616+}
1717+export interface RootAndTarget {
1818+ root: string
1919+ targetAbsPath: string
2020+}
2121+export type Context = RootAndTarget & {
2222+ rawErrsMap: RawErrsMap
2323+ openedDirs: Set<string>
2424+ lastActivePath?: string
2525+}
+17
packages/vitest/src/typecheck/utils.ts
···11+export const createIndexMap = (source: string) => {
22+ const map = new Map<string, number>()
33+ let index = 0
44+ let line = 1
55+ let column = 1
66+ for (const char of source) {
77+ map.set(`${line}:${column}`, index++)
88+ if (char === '\n' || char === '\r\n') {
99+ line++
1010+ column = 0
1111+ }
1212+ else {
1313+ column++
1414+ }
1515+ }
1616+ return map
1717+}
+38-7
packages/vitest/src/types/config.ts
···2727 [x: string]: unknown
2828}
29293030-export type VitestRunMode = 'test' | 'benchmark'
3030+export type VitestRunMode = 'test' | 'benchmark' | 'typecheck'
31313232export interface InlineConfig {
3333 /**
···443443 * Ignore any unhandled errors that occur
444444 */
445445 dangerouslyIgnoreUnhandledErrors?: boolean
446446+447447+ /**
448448+ * Options for configuring typechecking test environment.
449449+ */
450450+ typecheck?: Partial<TypecheckConfig>
451451+}
452452+453453+export interface TypecheckConfig {
454454+ /**
455455+ * What tools to use for type checking.
456456+ */
457457+ checker: 'tsc' | 'vue-tsc' | (string & Record<never, never>)
458458+ /**
459459+ * Pattern for files that should be treated as test files
460460+ */
461461+ include: string[]
462462+ /**
463463+ * Pattern for files that should not be treated as test files
464464+ */
465465+ exclude: string[]
466466+ /**
467467+ * Check JS files that have `@ts-check` comment.
468468+ * If you have it enabled in tsconfig, this will not overwrite it.
469469+ */
470470+ allowJs?: boolean
471471+ /**
472472+ * Do not fail, if Vitest found errors outside the test files.
473473+ */
474474+ ignoreSourceErrors?: boolean
475475+ /**
476476+ * Path to tsconfig, relative to the project root.
477477+ */
478478+ tsconfig?: string
446479}
447480448481export interface UserConfig extends InlineConfig {
449482 /**
450483 * Path to the config file.
451484 *
452452- * Default resolving to one of:
453453- * - `vitest.config.js`
454454- * - `vitest.config.ts`
455455- * - `vite.config.js`
456456- * - `vite.config.ts`
485485+ * Default resolving to `vitest.config.*`, `vite.config.*`
457486 */
458487 config?: string | undefined
459488···489518 shard?: string
490519}
491520492492-export interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters' | 'resolveSnapshotPath' | 'benchmark' | 'shard' | 'cache' | 'sequence'> {
521521+export interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters' | 'resolveSnapshotPath' | 'benchmark' | 'shard' | 'cache' | 'sequence' | 'typecheck'> {
493522 mode: VitestRunMode
494523495524 base?: string
···526555 shuffle?: boolean
527556 seed?: number
528557 }
558558+559559+ typecheck: TypecheckConfig
529560}
+3
packages/vitest/src/types/index.ts
···11import './vite'
22import './global'
3344+export { expectTypeOf, type ExpectTypeOf } from '../typecheck/expectTypeOf'
55+export { assertType, type AssertType } from '../typecheck/assertType'
66+export * from '../typecheck/types'
47export * from './config'
58export * from './tasks'
69export * from './reporter'
···11+// @ts-check
22+33+import { expectTypeOf, test } from 'vitest'
44+55+test('js test also works', () => {
66+ expectTypeOf(1).toEqualTypeOf(2)
77+})