CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-type-coverage

A CLI tool to check type coverage for typescript code

Pending
Overview
Eval results
Files

cli.mddocs/

Command Line Interface

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.

Capabilities

Basic Type Coverage Analysis

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.ts

Project Configuration

Specify the TypeScript project configuration.

-p, --project <string>     Path to tsconfig.json directory or file

Usage Examples:

# Use specific tsconfig.json
type-coverage -p ./src/tsconfig.json

# Use tsconfig.json in specific directory
type-coverage -p ./backend

Coverage Thresholds

Set 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 value

Usage Examples:

# Require at least 90% coverage
type-coverage --at-least 90

# Require exactly 95% coverage
type-coverage --is 95

Detailed Reporting

Control 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 format

Usage Examples:

# Show detailed results
type-coverage --detail --at-least 80

# JSON output for CI integration
type-coverage --json-output --at-least 90

Strict Mode Options

Enable 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 types

Usage Examples:

# Enable all strict checks
type-coverage --strict --at-least 95

# Custom strict configuration
type-coverage --ignore-catch --ignore-nested --at-least 90

File Filtering

Control 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 files

Usage 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-cwd

Performance and Caching

Enable caching for improved performance on large codebases.

--cache                    Enable result caching
--cache-directory <path>   Set custom cache directory location

Usage Examples:

# Enable caching (uses .type-coverage directory)
type-coverage --cache --at-least 90

# Use custom cache directory
type-coverage --cache --cache-directory ./build/.type-coverage

Configuration Management

Update package.json configuration based on results.

--update                   Update typeCoverage section in package.json
--update-if-higher         Update only if new coverage is higher

Usage Examples:

# Update package.json with current coverage
type-coverage --update

# Update only if coverage improved
type-coverage --update-if-higher

History and Tracking

Track coverage changes over time.

--history-file <filename>  Save coverage history to specified file

Usage Examples:

# Track coverage over time
type-coverage --history-file coverage-history.json --at-least 85

Error Reporting

Include 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 analysis

Usage Examples:

# Include semantic errors in analysis
type-coverage --report-semantic-error --detail

# Show debug information
type-coverage --debug --detail

Help and Version

Display help information and version details.

-h, --help                 Show help information
-v, --version              Show version number

Usage Examples:

# Show help
type-coverage --help

# Show version
type-coverage --version

Package.json Configuration

Type 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.

Exit Codes

0    Success - coverage meets requirements
1    Failure - coverage below threshold or errors occurred

Integration Examples

CI/CD Integration

# 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

Pre-commit Hooks

# With lint-staged - check only staged files
type-coverage -- $(git diff --cached --name-only --diff-filter=AM | grep '\\.ts$')

Progressive Migration

# Start with low threshold and gradually increase
type-coverage --at-least 70 --update-if-higher --history-file coverage-history.json

Install with Tessl CLI

npx tessl i tessl/npm-type-coverage

docs

cli.md

index.md

programmatic-api.md

tile.json