typeg

0.2.2 • Public • Published

Typeg

Typeg generates type definitions for TypeScript using decorators using Prettier.

@Times creates similar type definitions such as Promise.all easily.

Currently, It will only work where you can define TypeScript decorators.

class Promise {
  @Times(10, 'T', { args: { values: 'arrayMulti' }, returnType: 'arrayMulti' })
  all<T>(values: [T | PromiseLike<T>]): Promise<[T]>;
}
yarn typeg promise.d.ts --out _promise.d.ts
class Promise {
  all<T1>(values: [T1 | PromiseLike<T1>]): Promise<[T1]>;
  all<T1, T2>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>;
  all<T1, T2, T3>(
    values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>],
  ): Promise<[T1, T2, T3]>;
  all<T1, T2, T3, T4>(
    values: [
      T1 | PromiseLike<T1>,
      T2 | PromiseLike<T2>,
      T3 | PromiseLike<T3>,
      T4 | PromiseLike<T4>
    ],
  ): Promise<[T1, T2, T3, T4]>;
  ...
}

Other examples are here!

Usage

npm install -D prettier typeg
// or
yarn add -D prettier typeg
npx typeg <filepath> --out <dirpath>
// or
yarn typeg <filepath> --out <dirpath>

Use case

Readme

Keywords

none

Package Sidebar

Install

npm i typeg

Weekly Downloads

10

Version

0.2.2

License

MIT

Unpacked Size

24.8 kB

Total Files

11

Last publish

Collaborators

  • suguru03