Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/johanholmerin/ts-annotate
Auto-annotate TypeScript using runtime profiling
https://github.com/johanholmerin/ts-annotate
monkeytype pyannotate typeprof typescript
Last synced: about 1 month ago
JSON representation
Auto-annotate TypeScript using runtime profiling
- Host: GitHub
- URL: https://github.com/johanholmerin/ts-annotate
- Owner: johanholmerin
- License: mit
- Created: 2022-01-29T13:06:45.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-01-31T17:23:37.000Z (almost 3 years ago)
- Last Synced: 2024-11-19T11:38:15.826Z (about 2 months ago)
- Topics: monkeytype, pyannotate, typeprof, typescript
- Language: JavaScript
- Homepage:
- Size: 105 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ts-annotate
Automatically adds TypeScript declarations based on actual types passed at runtime, as determined by [V8][v8-profiling].
#### Before
```javascript
function add(a, b) {
return a + b;
}add(1, 2);
```#### After
```javascript
function add(a: number, b: number): number {
return a + b;
}add(1, 2);
```## Instructions
```sh
# 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
```## Supported 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`, arrays
`any[]`, and functions `(...args: any[]) => any`.## Commands
- `run` - Same as running `node` but saves type data to `ts-annotate-map.json`
- `apply` - Adds type declarations to the specified files using data in `ts-annotate-map.json`## Passing flags to Node
```sh
node --flag ./node_modules/.bin/ts-annotate ...
```## Prior work
- https://github.com/fhinkel/type-profile
[v8-profiling]: https://docs.google.com/document/d/1JY7pUCAk8gegyi6UkIdln6j_AeJqQucZg92advaMJY4/edit