Adds TypeScript type annotations using static analysis.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Circle CI NPM version Join the chat at Code Style: Prettier

Adds TypeScript type annotations using static analysis.

💀 Danger: new and experimental; use at your own risk! 💀


Type safety with TypeScript, especially when adding --noImplicitAny or --strictNullChecks, is wonderful but can be difficult to add to large pre-existing projects. Converting from JavaScript to TypeScript or improving type annotations through hundreds or thousands of legacy files is tedious and time-consuming.

This package automagically adds those missing type annotations for you with configurable comment markers. It can add...

TypeScript types on files freshly converted from JavaScript to TypeScript!

Fixes for --noImplicitAny across all your files with one command!

Missing nulls and undefineds to get you started with --strictNullChecks!

Doing so can allow you to enable these stricter compiler flags for all code without changing the runtime of existing code. Hooray! 💪

👉 Protip: also take a look at TypeWiz! 👈


npm i -g typestat

TypeStat can be installed globally or as a project dependency via npm/yarn.



This will use Cosmiconfig to search for a package.json "typestat" property or configuration file such to read settings from.

You can run on only a subset of files by passing globs to the command:

typestat src/demo/*.ts src/utils/**/*.ts

For instructions on the types of changes you can run with Typestat, see:

  1. for recommended steps to get started
  2. for the type of fixes TypeStat will generate mutations for
  3. for configuring how to rename types or add comments in mutations
  4. for details on which parts of source files TypeStat will change and how
  5. for using tsquery to ignore sections of source files
  6. Custom for including or creating custom mutators

Basic Flags


Path to a TypeStat configuration file, if you'd like a custom path.

typestat --config typestat.custom.json


Glob patterns of file names to include. You can specify these as arguments to the CLI and/or through your TypeStat configuration file. CLI includes will replace any configuration file includes.

typestat ./src/**/*.ts
    "include": [


Path to a TypeScript project file, if you'd like a path other than ./tsconfig.json.

typestat --project tsconfig.strict.json
    "project": "tsconfig.strict.json"

More advanced flags can be provided for:

  • Files
    • --fileAbove/files.above
    • --fileBelow/files.below
    • --fileConvertFileExtensions/files.convertFileExtensions
  • Filters
    • --filter/filter
  • Fixes:
    • --fixIncompleteTypes/fixes.incompleteTypes
    • --fixMissingProperties/fixes.missingProperties
    • --fixNoImplicitAny/fixes.noImplicitAny
    • --fixStrictNonNullAssertions/fixes.strictNonNullAssertions
  • Types:
    • --typeAlias/types.aliases
    • --typeMatching/types.matching
    • --typeOnlyPrimitives/types.onlyPrimitives
    • --typeStrictNullChecks/types.strictNullChecks


You can also run TypeStat via its JavaScript API:

import { typeStat } from "typestat";

    .then(result => {
        if (result.succeeded) {
            console.log(`Successfully ran TypeStat.`);
        } else {
            console.error(`Failed running TypeStat: ${result.error}`);

typeStat can optionally take in an object with most CLI/configuration settings. See TypeStatArgv:

await typeStat({
    config: "./typestat.custom.json",
await typeStat({
    config: "./typestat.custom.json",
    fixIncompleteTypes: true,
    fixNoImplicitAny: true,
    fixStrictNonNullAssertions: true,
    mutators: ["my-custom-mutator"],
    project: "./tsconfig.custom.json",