Check for existing type aliases given a custom type.
I was working on a project and while i was going through the code i was seeing a lot of duplicated types declaration so i took this opportunity to learn more about Typescript APIs
Say you have
// file1.ts
type NullableString = string | null
// file2.ts
type AnotherNullableString = string | null
TypeSentinel will tell you that you already have one or multiple type alias(es) with that exact same values, returning:
- the name of the type alias that you already have
- the usage count (how many times was that type alias used in your project)
TypeSentinel currently supports
- Types aliases with the same name
- Searching types with generics
- Interfaces declarations
By default it skips the node_modules
folder, but you can customize it with a config.json
{
"skip": ["node_modules", "sentinel.ts", "index.ts"],
"collectTypes": true
}
in the same path of your process.cwd()
.
npm link && typesentinel
pnpm tsc
- Make it executable
pnpm makex
- Add Shebang to ./build/index.js
#!/usr/bin/env node
// rest of the file
- Link
npm link
- Run it
typesentinel