Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

bio-dts

nikku1.1kMIT0.12.0

Generate sane and clean types from JavaScript sources

readme

bio-dts

CI

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 or through a simple generator cli.

Usage

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
  • Only exposed documented parameters
  • Validates, where needed declared parameters

Checkout the test fixtures for full coverage.

API

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);

changelog

Changelog

All notable changes to bio-dts are documented here. We use semantic versioning for releases.

Unreleased

Note: Yet to be released changes appear here.

0.12.0

  • FEAT: generate declarations for @overlord annoted functions in definition order (#6)
  • FEAT: consistently use locally provided TypeScript (#9)
  • FEAT: indicate TypeScript generation errors (be45fe8)
  • FIX: improve verbose behavior (#10)
  • CHORE: verify compatibility with TypeScript @overload annotations (#13)
  • DEPS: update to @babel/parser@7.26.3
  • DEPS: update to `recast@0.23.9`

Breaking Changes

  • generateTypes helper now requires you to explicitly pass the TypeScript instance used (#9)
  • Declarations for overloaded functions are now generated in definition order (#6)

0.11.0

  • FEAT: preserve comment style and position (#4)

0.10.0

  • FEAT: apply transforms additive

0.9.0

  • CHORE: add exports field, drop main field
  • CHORE: internal typing improvements

0.8.1

  • FIX: make JSDoc parsing more lenient
  • CHORE: add repository field (#1)
  • CHORE: log generate arguments in verbose mode

0.8.0

  • FEAT: clean undocumented arguments
  • FEAT: support @overlord - a working way to overload JS methods
  • CHORE: throw errors with location information

0.7.0

  • FEAT: preserve generics when generating overloads
  • FEAT: do not export type imports

0.6.1

  • FIX: correct handling of constructors (null return type)

0.6.0

  • FEAT: handle optional before non-optional in class properties

0.5.0

  • FEAT: support generated class properties

0.4.1

  • FIX: filter property from JSDoc comments

0.4.0

  • FEAT: support optional before non-optional parameters
  • FEAT: load local typescript
  • FIX: correct CLI directory check

0.3.0

  • FEAT: strip unneeded JSDoc tags

0.2.1

  • FIX: support multiple inherits statements per class

0.2.0

  • FEAT: pretty print output

0.1.2

  • FIX: make binary executable

0.1.1

  • FIX: correct executable path

0.1.0

Initial public release.