ts-retype
TypeScript icon, indicating that this package has built-in type declarations

0.3.0-dev.7 • Public • Published

tests CodeQL npm version coverage

TS retype

Discover duplicate TypeScript types in your codebase. TS retype finds duplicates of Literal and Interface types.

Install

npm install -g ts-retype

or

yarn global add ts-retype

Usage with CLI

ts-retype /path/to/project

or

npx ts-retype /path/to/project

Usage with Library

import { scan } from 'ts-retype';

const { data, meta } = scan({
    exclude: ['**/node_modules/**', '**/dist/**'],
    include: ['**/*.{ts,tsx}'],
    rootDir: '.',
});

console.log(meta);

for (const dup of data) {
    console.log(dup.group, dup.names, dup.files);
}

See Data Format for result format.

Configuration

CLI options

Usage: ts-retype [options] [rootDir]

Discover duplicate TypeScript types in your codebase.

Options:
  -V, --version                      output the version number
  -c, --config [file-path]           load config - if no path provided, loads
                                     .retyperc from current directory. if not
                                     set, use default config
  -e, --exclude [glob...]            glob patterns that will be ignored
  -g, --init [file-path]             initializes with default config. if no
                                     path is provided, creates .retyperc in the
                                     current directory
  -i, --include [glob...]            glob patterns that will be included in
                                     search
  -j, --json <file-path>             file path to export JSON report to. if not
                                     set, does not export JSON.
  -n, --noHtml                       if set, does not export HTML
  -o, --output <file-path|dir-path>  HTML report file path - if provided with
                                     dir, create index.html file inside the dir
  -h, --help                         display help for command

.retyperc

{
  "exclude": ["**/node_modules/**","**/dist/**"],
  "include": ["**/*.{ts,tsx}"],
  "json": "./apps/vis/src/assets/data.json",
  "noHtml": false,
  "output": "./retype-report.html",
  "rootDir": "."
}

Data Format

Defined in TypeDuplicate

export type TypeDuplicate = {
  files: {
    name: string;
    file: string;
    lines: [number, number];
    pos: [number, number];
    offset: number;
    type: 'interface' | 'literal' | 'alias' | 'function' | 'enum' | 'union';
    src: string;
    srcHgl?: TokenRoot;
    properties?: { name: string; type: string }[];
  }[];
  group: 'different' | 'renamed' | 'identical';
  names: { count: number; name: string }[];
  members?: string[];
  parameters?: { name: string; type: string }[];
  properties?: { name: string; type: string }[];
  returnType?: string;
  signature?: {
    name?: string;
    params: { name: string; type?: string }[];
    return?: string;
    strMin?: string;
    strFull?: string;
  };
  types?: string[];
};

Development

just clean
just install
just build-all
just test-all
just dev vis
just dev doc
just build-watch uikit
just rebuild uikit
just build uikit
just test search

Package Sidebar

Install

npm i ts-retype

Weekly Downloads

1

Version

0.3.0-dev.7

License

MIT

Unpacked Size

11.5 MB

Total Files

18

Last publish

Collaborators

  • petlack