Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marcalexiei/vitest-typechecking-playground
https://github.com/marcalexiei/vitest-typechecking-playground
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/marcalexiei/vitest-typechecking-playground
- Owner: marcalexiei
- Created: 2023-12-28T08:40:18.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-25T05:40:03.000Z (3 months ago)
- Last Synced: 2024-10-26T18:35:50.538Z (3 months ago)
- Language: TypeScript
- Size: 710 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Vitest typechecking playground
## Setup information
| Path | Has type error is source file | Has type error inside test file |
| ------------------------------- | ----------------------------- | ------------------------------- |
| src/doSomething | ❌ | ✅ |
| src/doSomethingWithTypeError.ts | ✅ | ❌ |From `vitest` 2.1 the workspace workaround should no longer be necessary:
From [Testing types documentation](https://vitest.dev/guide/testing-types.html#testing-types)
> Before Vitest 2.1, your typecheck.include overrode the include pattern,
> so your runtime tests did not actually run; they were only type-checked.
>
> Since Vitest 2.1, if your include and typecheck.include overlap,
> Vitest will report type tests and runtime tests as separate entries.![working with 2.1](docs/2.1-working.png)
> [!CAUTION]
>
> BELOW CONTENT IS NO LONGER VALIDFinding a way to perform typecheck on vitest using [--typecheck flag](https://vitest.dev/guide/testing-types.html#run-typechecking):
## Learned things
### How to get typechecking on both tests and source files
Include:
```js
test: {
typecheck: {
tsconfig: './tsconfig.test.json',
include: ['**/tests/**/*.spec.ts(x)?'],
},
},
```in `vite.config.js``
-
### Can't run js and ts check at the same time
When running with typecheck vitest doesn't perform runtime check and vice versa.
To solve the issue I used 2 separate workspaces:
![workspace std](./docs/workspace-run-std.png)
The result is what you see in the next image:
![error std](./docs/type-runtime-errors-std.png)