https://github.com/nikku/bio-dts
Generate type definitions from JavaScript
https://github.com/nikku/bio-dts
javascript type-generation
Last synced: over 1 year ago
JSON representation
Generate type definitions from JavaScript
- Host: GitHub
- URL: https://github.com/nikku/bio-dts
- Owner: nikku
- Created: 2023-03-11T02:27:00.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-01-10T22:31:25.000Z (over 1 year ago)
- Last Synced: 2025-03-12T04:35:17.058Z (over 1 year ago)
- Topics: javascript, type-generation
- Language: JavaScript
- Homepage:
- Size: 307 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# bio-dts
[](https://github.com/nikku/bio-dts/actions/workflows/CI.yml)
Utilities to generate sane and clean type definitions from JavaScript files.
## About
This module provides `pre` and `post` processing helpers to a type definition pipeline.
You can use it [via API](#api) or through a simple [generator cli](#usage).
## Usage
```sh
npx bio-dts --outDir dist/types -r lib
```
## Features
Generates clean type definitions from ES5 code bases:
* ES5 prototypical classes + inheritance
* Optional parameters before required ones
* Function overloading (via `@overlord` annotations, actually works!)
* Converts JSDoc to [TSDoc](https://github.com/microsoft/tsdoc)
* Only exposed documented parameters
* Validates, where needed declared parameters
Checkout the [test fixtures](./test/fixtures) for full coverage.
## API
```js
import {
preTransform,
postTransform,
generateTypes
} from 'bio-dts';
import * as typescript from 'typescript';
// transform JS so it keeps the shape,
// but is properly digestable by the typescript
// compiler
const transformedCode = preTransform(jsCode);
// post process typescript compiler type code
// removing internals, and fixing up the definitions
const transformedCode = postTransform(tsCode);
// execute the full pipeline, including invoking the
// typescript compiler
generateTypes(files, {
outDir: 'dist'
}, typescript);
```