npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

typehunt

v0.1.2

Published

Find duplicate type/interface/enum definitions across a TypeScript codebase (name + shape matching).

Downloads

18

Readme

TypeHunt

npm version license

Hunt down duplicate TypeScript declarationstype, interface, and enum — across your codebase.

TypeHunt scans your source files, extracts declarations via the TypeScript Compiler API, and reports duplicates by:

  • Name: the same identifier declared in multiple files
  • Shape: structurally identical declarations hiding behind different names

Node.js 18+ required


Install

# Add to your project (recommended)
npm i -D typehunt

# Or install globally
npm i -g typehunt

Quick Start

# Scan the src/ directory (default)
npx typehunt

# Use your tsconfig to determine which files to scan (respects include/exclude/extends)
npx typehunt --tsconfig tsconfig.json

# Output as JSON (great for tooling)
npx typehunt --json

# Generate a Markdown report (PR-friendly)
npx typehunt --md --output report.md

# Fail in CI when duplicates are found
npx typehunt --fail-on-duplicates

How It Works

TypeHunt parses .ts, .tsx, .mts, and .d.ts files and extracts declarations. It then groups them in two ways:

Name matching

Finds declarations with the same identifier declared in multiple files.

Shape matching

Finds declarations that are structurally identical even if they have different names.

The comparison normalizes whitespace, strips comments, replaces the name with a placeholder, and normalizes interfacetype shape differences.

Example that will be detected as the same shape:

// src/models/user.ts
interface UserResponse {
  id: string;
  name: string;
  email: string;
}

// src/api/types.ts
type UserDTO = {
  id: string;
  name: string;
  email: string;
};

Example Output

── Summary ──────────────────────────────────────────────
  Files scanned:          124
  Declarations found:     312
  Source:                 directory walk (src)
  Duplicate name groups:  3
  Duplicate shape groups: 5

── Duplicate type names ──────────────────────────────────

  User (3 occurrences)
    interface  src/models/user.ts:5
    interface  src/api/types.ts:12
    type       src/shared/types.ts:28

── Duplicate type shapes ─────────────────────────────────

  shape#1 — names: UserResponse, UserDTO (2 occurrences)
    interface  UserResponse              src/models/user.ts:5
    type       UserDTO                   src/api/types.ts:12
    shape:   type __NAME__ = { id: string; name: string; email: string; }

CLI Options

Usage:
  npx typehunt [options]

Options:
  --root <path>                  Root directory to scan (default: src)
  --tsconfig <path>              Path to tsconfig.json — respects include/exclude
  --mode <name|shape|both>       Duplicate detection mode (default: both)
  --min <number>                 Minimum duplicates per group (default: 2)

  --exclude <token,...>          Exclude by matching tokens against relative paths (repeatable).
                                 Match rules: equals, prefix (token/...), or substring.

  --no-enums                     Skip enum declarations
  --include-reexports            Include re-exports (excluded by default)

  --format <text|json|markdown>  Output format (default: text)
  --json                         Shortcut for --format json
  --markdown, --md               Shortcut for --format markdown
  --output <path>                Save output to a file

  --fail-on-duplicates           Exit with code 1 when duplicates are found
  --help, -h                     Show this help

Output Formats

Text (default)

Readable output printed to the terminal.

JSON

npx typehunt --json

Useful for programmatic consumption (dashboards, CI annotations, custom checks).

{
  "filesScanned": 124,
  "declarationsScanned": 312,
  "duplicateNameGroups": [
    {
      "name": "User",
      "count": 3,
      "declarations": [
        {
          "file": "src/models/user.ts",
          "line": 5,
          "kind": "interface",
          "name": "User",
          "isReExport": false
        }
      ]
    }
  ]
}

Markdown

npx typehunt --md --output report.md

Generates a formatted report with tables — perfect for PRs and internal docs.


CI Integration

Use --fail-on-duplicates to make TypeHunt exit with code 1 when duplicates are detected:

# GitHub Actions example
- name: Check for duplicate TypeScript declarations
  run: npx typehunt --fail-on-duplicates

Excluding Files

The --exclude flag accepts comma-separated tokens (and is repeatable). A file is excluded if any token matches its relative path by exact match, prefix, or substring:

# Exclude generated code and vendor directories
npx typehunt --exclude generated,vendor

# Repeatable flag
npx typehunt --exclude generated --exclude __tests__

When using --tsconfig, the tsconfig's own include/exclude rules are applied first, then --exclude filters further.


Re-exports

By default, re-exports like export { Foo } from "./bar" are excluded because they don't introduce new declarations and can add noise in "barrel export" codebases.

Use --include-reexports if you want to include them in analysis.


License

MIT