Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
T

type-coverage

> 编程语言
Open source

A CLI tool to check type coverage for typescript code

1.3K stars0 likes1 views
WebsiteGitHub

About

A CLI tool to check type coverage for typescript code

type-coverage

A CLI tool to check type coverage for typescript code

This tool will check type of all identifiers, the type coverage rate = the count of identifiers whose type is not any / the total count of identifiers, the higher, the better.

use cases

  • Show progress of long-term progressive migration from existing js code to typescript code.
  • Avoid introducing accidental any by running in CI.
  • Show progress of long-term progressive migration from existing looser typescript code to stricter typescript code.migrate to stricter typescript

install

yarn global add type-coverage typescript

usage

run type-coverage

arguments

name type description
-p, --project string? tell the CLI where is the tsconfig.json(Added in v1.0)
--detail boolean? show detail(Added in v1.0)
--at-least number? fail if coverage rate foo(Added in v2.16`)
--ignore-non-null-assertion boolean? ignore non-null assertion, eg: foo!(Added in v2.16)
--ignore-object boolean? Object type not counted as any, eg: foo: Object(Added in v2.21)
--ignore-empty-type boolean? empty type not counted as any, eg: foo: {}(Added in v2.21)
--show-relative-path boolean? show relative path in detail message(Added in v2.17)
--history-file string? file name where history is saved(Added in v2.18)
--no-detail-when-failed boolean? not show detail message when the CLI failed(Added in v2.19)(Use --no-detail-when-failed=true to enable it )
--report-semantic-error boolean? report typescript semantic error(Added in v2.22)
-- file1.ts file2.ts ... string[]? only checks these files, useful for usage with tools like lint-staged(Added in v2.23)
--cache-directory string? set cache directory(Added in v2.24)
--not-only-in-cwd boolean? include results outside current working directory(Added in v2.26)
--json-output boolean? output results as JSON(Added in v2.27)
--report-unused-ignore boolean? report unused ignore line directives, enabled if --strict(Added in v2.28)

strict mode

If the identifiers' type arguments exist and contain at least one any, like any[], ReadonlyArray, Promise, Foo, it will be considered as any too(Added in v1.7)

Type assertion, like foo as string, foo!, foo will be considered as uncovered, exclude foo as const, foo, foo as unknown(Added in v2.8), and other safe type assertion powered by isTypeAssignableTo(Added in v2.9)

Object type(like foo: Object) and empty type(like foo: {}) will be considered as any(Added in v2.21)

Strict mode enables --report-unused-ignore by default.

Also, future minor release may introduce stricter type check in this mode, which may lower the type coverage rate

enable cache

save and reuse type check result of files that is unchanged and independent of changed files in .type-coverage directory(or set by --cache-directory), to improve speed

ignore catch

If you want to get 100% type coverage then try {} catch {} is the largest blocked towards that.

This can be fixed in typescript with Allow type annotation on catch clause variable but until then you can turn on --ignore-catch --at-least 100.

Your catch blocks should look like

typescript
try {
  await ...
} catch (anyErr) {
  const err =  anyErr
}

To have the highest type coverage.

ignore files

This tool will ignore the files, eg: --ignore-files "demo1/*.ts" --ignore-files "demo2/foo.ts"

config in package.json

…

ignore line

Use type-coverage:ignore-next-line or type-coverage:ignore-line in comment(// or /* */) to ignore any in a line.(Added in v1.9)

typescript
try {
  // type-coverage:ignore-next-line
} catch (error) { // type-coverage:ignore-line
}

The --report-unused-ignore or --strict can report unused ignore line directives.(Added in v2.28)

…

The typescript language service plugin of type-coverage(Added in v2.12)

yarn add ts-plugin-type-coverage -D

json5
{
  "compilerOptions": {
    "plugins": [
      {
        "name": "ts-plugin-type-coverage",
        "strict": true, // for all configurations, see LintOptions above
        "ignoreCatch": true,
      }
    ]
  }
}

For VSCode users, choose "Use Workspace Version", See , or just use the wrapped plugin below.

VSCode plugin(Added in v2.13)

Configuration is in Preferences - Settings - Extensions - Type Coverage

If the result from the vscode plugin is different from the result from the CLI, maybe your project root directory's tsconfig.json is different from your CLI tsconfig.json

If the plugin does not work, you may see some workarounds:

FAQ

Q: Does this count JavaScript files?

Yes, This package calls Typescript API, Typescript can parse Javascript file(with allowJs), then this package can too.

Q: How to disable color in output?

Set the environment variable FORCE_COLOR=0 or use --no-color option, see chalk documentation for details.

Changelogs

CHANGELOG for minor and patch release

v2

  1. Move typescript from dependencies to peerDependencies
  2. Move API from package type-coverage to package type-coverage-core
typescript
// v1
import { lint } from 'type-coverage'
lint('.', false, false, undefined, undefined, true)

// v2
import { lint } from 'type-coverage-core'
lint('.', { strict: true })

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言