Automatically adds TypeScript declarations based on actual types passed at runtime, as determined by V8.
function add(a, b) { return a + b; } add(1, 2);function add(a: number, b: number): number { return a + b; } add(1, 2);# 1. Generate type data by running the code npx ts-annotate run ./src/index.js # 2. Add type declaration to source code npx ts-annotate apply ./src/**/*.js # 3. Rename .js to .ts # 4. Cleanup/improve types- Primitives -
string,number,boolean, etc. - Class instances(includes arrays, objects, promises, etc.)
- Functions(i.e. callbacks)
Only simple types are inferred - objects are Record<string, any>, arrays any[], and functions (...args: any[]) => any.
run- Same as runningnodebut saves type data tots-annotate-map.jsonapply- Adds type declarations to the specified files using data ints-annotate-map.json
node --flag ./node_modules/.bin/ts-annotate ...