Mutation Testing Implementation in TypeScript
14-day free trial
Try SeekerPro free for 14 days.
Full access while you try it · then $15.99/mo · cancel anytime
Start your 14-day free SeekerPro trial →30-day money-back guarantee · Cancel anytime
Not checking a site today? Turn this topic into a ready to paste AI prompt, free →
Key Takeaways
- ✓Mutation Testing runs in O(n²) time and O(n) space, in TypeScript as in every other language.
- ✓Stryker again, but with a capability that only exists for typed languages: the @stryker-mutator/typescript-checker plugin type-checks every mutant before running it.
- ✓Always install the typescript-checker plugin alongside Stryker on a TypeScript project. Without it the score is inflated and misleading; with it the score reflects only mutants that represent genuinely possible programs.
- ✓The TypeScript trap: Skipping the checker is the mistake, and it fails in the flattering direction. A mutant that changes a string literal to an empty string may violate a template literal type or a discriminated union and fail to compile, the test run then errors, Stryker records the mutant as killed, and your mutation score goes UP for a reason that has nothing to do with your tests.
- ✓Type checking each mutant is not free, but the plugin reuses a single incremental TypeScript program rather than starting the compiler per mutant, so it typically adds a modest fraction to total runtime.
What Mutation Testing actually is
Mutation Testing in TypeScript: what you actually reach for
TypeScript implementation
// npm i -D @stryker-mutator/core @stryker-mutator/typescript-checker
// stryker.config.json
{
"testRunner": "vitest",
"mutate": ["src/**/*.ts", "!src/**/*.spec.ts"],
// Without this, mutants that DO NOT COMPILE are counted as "killed"
// and the score is inflated by the type system rather than by tests.
"checkers": ["typescript"],
"tsconfigFile": "tsconfig.json",
"coverageAnalysis": "perTest",
"incremental": true,
"thresholds": { "high": 85, "low": 75, "break": 70 }
}
// Report now distinguishes three outcomes, not two:
//
// Killed 412 a test failed -> the behaviour is pinned
// Survived 23 tests passed -> NO test asserts this line
// CompileError 67 not a valid program, excluded from the score
//
// Only "Survived" is a finding. Triage by blast radius: a survivor in
// money or auth code outranks twenty in formatting helpers.Think Your Code Is Clean? Let NexusBro QA It in 20 Seconds.
Paste your code. Click QA. Get an instant expert-level audit with fixes.
QA My Code FreeThe TypeScript-specific trap
Performance in TypeScript, beyond the O(n²)
Real-World Applications
Interview Tips & Practice
Frequently Asked Questions
Which TypeScript type or library should I use for Mutation Testing?
Stryker again, but with a capability that only exists for typed languages: the @stryker-mutator/typescript-checker plugin type-checks every mutant before running it. Mutants that do not compile are reported as CompileError and excluded from the denominator instead of being counted as killed.
What is the most common TypeScript mistake when implementing Mutation Testing?
Skipping the checker is the mistake, and it fails in the flattering direction. A mutant that changes a string literal to an empty string may violate a template literal type or a discriminated union and fail to compile, the test run then errors, Stryker records the mutant as killed, and your mutation score goes UP for a reason that has nothing to do with your tests. A score computed without the type checker is not comparable to one computed with it, so never mix the two across runs.
How does Mutation Testing actually perform in TypeScript?
Type checking each mutant is not free, but the plugin reuses a single incremental TypeScript program rather than starting the compiler per mutant, so it typically adds a modest fraction to total runtime. That cost is almost always repaid, because every mutant eliminated as a CompileError is one that does not need a full test run. Combine it with coverageAnalysis: "perTest" and incremental mode. Time complexity is O(n²) and space is O(n).
Related Articles
Rather try before you buy?
Get the rest of the vault: every cheat sheet, guide and audit in SeekerPro, free for 14 days, then $15.99/mo. Cancel anytime. Daily usage limits apply.
Start my 14-day SeekerPro trialStudying for this? Devin free tiers and academic plans are laid out on Noizz.
Is your site built to last?
Run a free QA audit and get your Site Health Score in seconds.
Check Your Site FreeNo signup required
Reader comments
No account needed. Share what worked, what did not, and what you would add.
Add your take below. A concrete tip, a result or a question helps the next reader most.