A CLI tool to check type coverage for typescript code
—
The type-coverage CLI provides comprehensive options for measuring and reporting TypeScript type coverage in projects. It analyzes TypeScript code to calculate the percentage of identifiers with explicit types versus 'any' types.
Check type coverage for a TypeScript project.
type-coverage [options] [-- file1.ts file2.ts ...]Usage Examples:
# Basic coverage check
type-coverage
# Check specific project
type-coverage -p ./tsconfig.json
# Check only specific files
type-coverage -- src/main.ts src/utils.tsSpecify the TypeScript project configuration.
-p, --project <string> Path to tsconfig.json directory or fileUsage Examples:
# Use specific tsconfig.json
type-coverage -p ./src/tsconfig.json
# Use tsconfig.json in specific directory
type-coverage -p ./backendSet minimum coverage requirements and fail if not met.
--at-least <number> Fail if coverage rate < this value
--is <number> Fail if coverage rate !== this exact valueUsage Examples:
# Require at least 90% coverage
type-coverage --at-least 90
# Require exactly 95% coverage
type-coverage --is 95Control the level of detail in coverage reports.
--detail Show detailed results with file locations
--no-detail-when-failed Hide details when coverage check fails
--show-relative-path Show relative paths instead of absolute paths
--json-output Output results as JSON formatUsage Examples:
# Show detailed results
type-coverage --detail --at-least 80
# JSON output for CI integration
type-coverage --json-output --at-least 90Enable strict checking modes for higher type safety standards.
--strict Enable strict mode (includes all strict options)
--ignore-catch Ignore catch clause variables
--ignore-nested Ignore any in type arguments (Promise<any>)
--ignore-as-assertion Ignore as assertions (foo as string)
--ignore-type-assertion Ignore type assertions (<string>foo)
--ignore-non-null-assertion Ignore non-null assertions (foo!)
--ignore-object Don't count Object type as any
--ignore-empty-type Don't count empty type {} as any
--ignore-unread Allow writes to variables with implicit any typesUsage Examples:
# Enable all strict checks
type-coverage --strict --at-least 95
# Custom strict configuration
type-coverage --ignore-catch --ignore-nested --at-least 90Control which files are included in the analysis.
--ignore-files <patterns> Ignore files matching glob patterns (can be repeated)
--not-only-in-cwd Include results outside current working directory
-- <files> Only check specified filesUsage Examples:
# Ignore test files and generated code
type-coverage --ignore-files "**/*.test.ts" --ignore-files "**/generated/**"
# Check only specific files (useful with lint-staged)
type-coverage -- src/main.ts src/utils.ts
# Include files outside current directory
type-coverage --not-only-in-cwdEnable caching for improved performance on large codebases.
--cache Enable result caching
--cache-directory <path> Set custom cache directory locationUsage Examples:
# Enable caching (uses .type-coverage directory)
type-coverage --cache --at-least 90
# Use custom cache directory
type-coverage --cache --cache-directory ./build/.type-coverageUpdate package.json configuration based on results.
--update Update typeCoverage section in package.json
--update-if-higher Update only if new coverage is higherUsage Examples:
# Update package.json with current coverage
type-coverage --update
# Update only if coverage improved
type-coverage --update-if-higherTrack coverage changes over time.
--history-file <filename> Save coverage history to specified fileUsage Examples:
# Track coverage over time
type-coverage --history-file coverage-history.json --at-least 85Include additional error reporting and diagnostics.
--report-semantic-error Report TypeScript semantic errors
--report-unused-ignore Report unused type-coverage ignore directives
--debug Show debug information during analysisUsage Examples:
# Include semantic errors in analysis
type-coverage --report-semantic-error --detail
# Show debug information
type-coverage --debug --detailDisplay help information and version details.
-h, --help Show help information
-v, --version Show version numberUsage Examples:
# Show help
type-coverage --help
# Show version
type-coverage --versionType coverage can be configured via package.json to avoid repeating CLI arguments:
{
"typeCoverage": {
"atLeast": 90,
"detail": true,
"strict": true,
"ignoreCatch": true,
"ignoreFiles": ["**/*.test.ts", "**/generated/**"],
"ignoreUnread": false,
"showRelativePath": true,
"cache": true
}
}CLI arguments override package.json configuration when both are present.
0 Success - coverage meets requirements
1 Failure - coverage below threshold or errors occurred# GitHub Actions / Jenkins
type-coverage --at-least 90 --no-detail-when-failed
# Generate coverage report for artifacts
type-coverage --json-output --detail > coverage-report.json# With lint-staged - check only staged files
type-coverage -- $(git diff --cached --name-only --diff-filter=AM | grep '\\.ts$')# Start with low threshold and gradually increase
type-coverage --at-least 70 --update-if-higher --history-file coverage-history.jsonInstall with Tessl CLI
npx tessl i tessl/npm-type-coverage