vitest-dev / vitest-dev/vitest
Provide custom tsc cli flags for typechecking
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 17.1k
- Forks
- 2k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 94
Description
Clear and concise description of the problem
When testing types with --typecheck.enabled, I tend to use different tsconfig.json files to, for instance, test a) from source files during development, and b) against generated declaration files. However, the differences between some tsconfig files may be minimal, so some of them may look like this:
// tsconfig.x-alt.json
{
"extends": "./tsconfig.x.json",
"compilerOptions": {
"paths": null
}
}
The creation of additional tsconfig files that override a few tsc options could be prevented if those tsc options could instead be provided as tsc cli flags through vitest's cli.
Suggested solution
A new --typecheck.flags option could be introduced for vitest to run tsc with additional cli flags:
# tsconfig path defined in vitest.config.ts
# Regular typecheck
vitest run --typecheck.only
# Run tsc with --customConditions null
vitest run --typecheck.only --typecheck.flags "--customConditions null"
Alternative
I'm not sure if there is an issue with the argument of --typecheck.flags requiring enclosing quotes. If there is, an alternative may be to define an object of flags in vitest.config.ts, and select which flags to apply with the object's keys through vitest's cli:
// vitest.config.ts
export default defineConfig({
test: {
typecheck: {
tsconfig: "./path/to/tsconfig.json",
flags: {
customFlags: "--customConditions null"
}
}
}
})
vitest run --typecheck.only --typecheck.flags customFlags
This is not as flexible, but still allows to more conveniently define tsc option overrides.
Additional context
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The payload names no files or tests; start by tracing Vitest’s existing --typecheck.only CLI handling and the tsc invocation. Define how custom flags are accepted and forwarded, then verify a typecheck run with --typecheck.flags avoids requiring a second tsconfig.json.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli, testing-qa, tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100