This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This project generates alternative TypeScript standard library definitions with improved type safety. The architecture consists of:
-
build/- TypeScript build system and generation logiclib.ts- Main script for generating improved lib definitionspackage.ts- Script for building npm packagesdiff.ts- Script for generating documentation diffslogic/- Core generation logic and AST manipulation
-
lib/- Source TypeScript lib definition improvements (what gets applied to TypeScript's built-in libs) -
generated/- Output directory for processed TypeScript lib files -
dist-package/- Individual npm packages for each TypeScript lib (e.g., es2015, dom, etc.) -
TypeScript/- Git submodule containing the official TypeScript repository for source lib files- Note:
TypeScript/lib/lib.dom.d.tsandTypeScript/lib/lib.es5.d.tsare HUGE. Never try to read the whole file at once. Always grep for specific parts.
- Note:
-
tests/- Type-level tests usingtsdto verify the improved type definitions work correctly
# Compile TypeScript build scripts
npm run build:tsc
# Generate improved lib files from TypeScript source + better-typescript-lib improvements
npm run build:lib
# Build npm packages for distribution
npm run build:package
# Generate documentation diffs
npm run build:diffNOTE that you should run npm run build:lib and then npm run build:package before running tests to ensure the latest changes are reflected.
# Run type-level tests in tests/ directory
cd tests && npm test
# Or run tsd directly
cd tests && npx tsd- Modify type definitions in
lib/directory - Run
npm run build:lib && npm run build:generateto regenerate the output - Test changes with
cd tests && npm test
NOTE that the generated type definitions only take effect during the tests. When you want to debug the generated types, the only way is to write a test case in the tests/ directory and run npm test to see how the types behave. Do not forget to run npm run build:lib && npm run build:generate after modifying the source definitions in lib/.
- Uses AST manipulation to apply improvements to TypeScript's standard library definitions
- Generates separate npm packages that TypeScript automatically detects and uses (via
@typescript/lib-*naming) - The
ReplacementMapsystem tracks which parts of the original TypeScript libs should be replaced with improved versions - Type improvements focus on replacing
anywith more specific types likeJSONDataforJSON.parse() - All changes prioritize type safety over convenience, potentially causing breaking changes in existing codebases
build/logic/generate.ts- Core generation algorithmbuild/logic/ReplacementMap.ts- Tracks lib modificationslib/es5.d.ts- Main improvements to core JavaScript APIstests/src/- Type-level tests for verifications