or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

cli.mdindex.mdprogrammatic-api.md
tile.json

tessl/npm-type-coverage

A CLI tool to check type coverage for typescript code

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/type-coverage@2.29.x

To install, run

npx @tessl/cli install tessl/npm-type-coverage@2.29.0

index.mddocs/

Type Coverage

Type Coverage is a comprehensive CLI tool and library for measuring TypeScript type coverage in codebases. It calculates the percentage of identifiers that have explicit types versus 'any' types, enabling developers to track and improve type safety during progressive migration from JavaScript to TypeScript.

Package Information

  • Package Name: type-coverage
  • Package Type: npm
  • Language: TypeScript/JavaScript
  • Installation: npm install -g type-coverage typescript

Core Imports

CLI usage (global installation):

type-coverage

For programmatic usage:

import { lint, lintSync, FileAnyInfoKind } from "type-coverage-core";

CommonJS:

const { lint, lintSync, FileAnyInfoKind } = require("type-coverage-core");

Basic Usage

CLI usage:

# Basic type coverage check
type-coverage

# Check with minimum threshold
type-coverage --at-least 90

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

# Use with specific project
type-coverage -p ./tsconfig.json --detail

Programmatic usage:

import { lint } from "type-coverage-core";

// Analyze project type coverage
const result = await lint("./", {
  strict: true,
  detail: true,
  enableCache: true
});

console.log(`Coverage: ${result.correctCount}/${result.totalCount} (${(result.correctCount/result.totalCount*100).toFixed(2)}%)`);

Architecture

Type Coverage consists of two main components:

  • CLI Tool: Command-line interface providing comprehensive options for type coverage analysis and reporting
  • Core Library: Programmatic API (type-coverage-core) for integrating type coverage analysis into build pipelines and development tools
  • Type Analysis Engine: Deep TypeScript AST analysis to identify 'any' types, unsafe assertions, and type coverage metrics
  • Caching System: Performance optimization through intelligent caching of unchanged files
  • Configuration System: Support for both CLI arguments and package.json configuration

Capabilities

Command Line Interface

Comprehensive CLI tool with 20+ options for measuring and reporting TypeScript type coverage. Supports thresholds, detailed reporting, caching, and integration with CI/CD pipelines.

type-coverage [options] [-- file1.ts file2.ts ...]

Key CLI options:

-p, --project <string>          Path to tsconfig.json
--at-least <number>            Fail if coverage < this value
--detail                       Show detailed results
--strict                       Enable strict mode checking
--cache                        Enable result caching
--ignore-files <patterns>      Ignore specific files/patterns
--json-output                  Output results as JSON

Command Line Interface

Programmatic API

Core library API for integrating type coverage analysis into custom tools, build systems, and development workflows.

function lint(
  project: string, 
  options?: Partial<LintOptions>
): Promise<{
  correctCount: number;
  totalCount: number;
  anys: AnyInfo[];
  program: ts.Program;
  fileCounts: Map<string, Pick<FileTypeCheckResult, 'correctCount' | 'totalCount'>>;
}>;

function lintSync(
  compilerOptions: ts.CompilerOptions,
  rootNames: string[],
  options?: Partial<LintOptions>
): {
  correctCount: number;
  totalCount: number;
  anys: Array<AnyInfo & { sourceFile: ts.SourceFile }>;
  program: ts.Program;
  fileCounts: Map<string, Pick<FileTypeCheckResult, 'correctCount' | 'totalCount'>>;
};

interface LintOptions {
  debug: boolean;
  strict: boolean;
  enableCache: boolean;
  ignoreFiles?: string | string[];
  ignoreCatch: boolean;
  ignoreUnreadAnys: boolean;
  ignoreNested: boolean;
  ignoreAsAssertion: boolean;
  ignoreTypeAssertion: boolean;
  ignoreNonNullAssertion: boolean;
  ignoreObject: boolean;
  ignoreEmptyType: boolean;
  reportSemanticError: boolean;
  reportUnusedIgnore: boolean;
  fileCounts: boolean;
  files?: string[];
  cacheDirectory?: string;
  notOnlyInCWD?: boolean;
}

Programmatic API

Types

interface AnyInfo {
  file: string;
  line: number;
  character: number;
  text: string;
  kind: FileAnyInfoKind;
}

interface FileTypeCheckResult {
  correctCount: number;
  totalCount: number;
  anys: FileAnyInfo[];
}

interface FileAnyInfo {
  line: number;
  character: number;
  text: string;
  kind: FileAnyInfoKind;
}

enum FileAnyInfoKind {
  any = 1,                    // any type
  containsAny = 2,           // Promise<any>
  unsafeAs = 3,              // foo as string
  unsafeTypeAssertion = 4,   // <string>foo
  unsafeNonNull = 5,         // foo!
  semanticError = 6,         // TypeScript semantic errors
  unusedIgnore = 7           // Unused ignore directives
}