partial-ts-check
v0.1.0-beta.0
Published
CLI to run TypeScript checks and report only whitelisted files, ignoring blacklisted files.
Maintainers
Readme
partial-ts-check
⚠️ Beta Version: This package is currently in beta and was written mostly via AI under human supervision. Pull requests, advice, and feature requests are welcome through GitHub Issues!
A tiny CLI that runs tsc --noEmit and reports only TypeScript errors from whitelisted files while ignoring blacklisted files.
Perfect for migrating JavaScript codebases to TypeScript. When you start converting files and making them error-free, but the entire project still contains many errors, this tool lets you define which files to check.
Use it in git hooks to prevent commits with errors in already-migrated files, while allowing work to continue on files that haven't been migrated yet.
Install
npm install --save-dev partial-ts-check
# or
pnpm add -D partial-ts-checkImportant: Make sure you have typescript installed in your project:
npm install --save-dev typescript
# or
pnpm add -D typescriptUsage
1. Configure in your project
Add a "partial-ts-check" block to your project's package.json:
{
"partial-ts-check": {
"whitelist": "ts-whitelist.js",
"blacklist": "ts-blacklist.js",
"printFilesList": true,
"tsconfig": "tsconfig.json"
}
}Configuration options:
whitelist/whiteList: path to a.jsor.cjsfile that exports an array of file patterns to includeblacklist/blackList: path to a.jsor.cjsfile that exports an array of file patterns to excludeprintFilesList(optional): show short non-whitelisted errors (default: true)tsconfig(optional): path to your tsconfig (default:tsconfig.json)
2. Create whitelist and blacklist files
Create .js or .cjs files that export an array of file patterns. You can use any part of the file path - full paths, folder names, or partial paths to match multiple files.
Example ts-whitelist.js:
// Files that must be error-free
export default [
"src/components/", // All files in components folder
"src/utils/helpers.ts", // Specific file
"src/auth/" // All files in auth folder
];Example ts-blacklist.js:
// Files to ignore completely
export default [
"src/legacy/", // All files in legacy folder
"src/vendor/", // All files in vendor folder
".test.ts", // All test files
"generated/" // Any generated folder
];3. Add a script
Add a script to your package.json:
{
"scripts": {
"ts:check-partial": "partial-ts-check"
}
}Then run:
npm run ts:check-partial
# or
pnpm ts:check-partial4. Use in git hooks (recommended)
To prevent commits with errors in whitelisted files, add it to your pre-commit hook.
Using husky:
npx husky init
echo "npm run ts:check-partial" > .husky/pre-commitUsing lefthook:
Add to your lefthook.yml:
pre-commit:
commands:
ts-check:
run: npm run ts:check-partialUsing lint-staged:
{
"lint-staged": {
"*.ts": "partial-ts-check"
}
}How it works
- Resolves and runs your local
node_modules/typescript/bin/tscwith--noEmit - Parses output, ignores blacklisted files, includes only whitelisted files
- Exits non-zero if there are errors in whitelisted files; otherwise prints a short summary for the rest
Note: This tool uses the TypeScript compiler installed in your project, so make sure you have the typescript package installed as a dependency.
Requirements
- Node >= 18
typescriptinstalled in the consuming project
Contributing
See DEVELOPMENT.md for information about local development and testing.
License
MIT
