Skip to content
forked from whxaxes/js2dts

d.ts generator for javascript

License

Notifications You must be signed in to change notification settings

jiyeking/js2dts

 
 

Repository files navigation

js2dts

this project is fork by https://github.com/whxaxes/js2dts.git , and add features:

orgin describ

NPM version Package Quality Build Status Appveyor status Test coverage NPM download

Generate dts for javascript

TS has support generating d.ts for js by flags(allowJs and declarations) in version 3.7 . So this project will not maintained anymore. ( eg. tsc --allowJs --declaration --emitDeclarationOnly myfile.js )

Install

npm i js2dts -g

or

yarn global add js2dts

Usage

Usage: j2d [options] <file>

Options:
  -v, --version      output the version number
  -d, --dist [path]  Create dts to giving path (default to the same dir as file)
  -t, --terminal     Output the result to terminal instead of writing file to disk
  --no-prefix        The generated code will has no prefix
  --ignore-private   Private properties are also being export
  -h, --help         output usage information

Example

$ j2d ./test.js

or

$ js2dts ./test.js

Example

source code

// function/index.js
module.exports = superName;

/**
 * super function
 *
 * @param {String} bbb 123123
 */
function superName(bbb, ccc = module.exports.test) {
  return '123123';
}

module.exports.test = () => 123123;
module.exports.test2 = {
  abc: 123,
};

output dts

// function/index.d.ts
interface T104 {
  test: () => number;
  test2: _Function.T105;
}
/**
 * super function
 *
 * @param {String} bbb 123123
 */
declare function superName(bbb: string, ccc?: () => number): string;
declare const _Function: typeof superName & T104;
declare namespace _Function {
  export interface T105 {
    abc: number;
  }
}
export = _Function;

More example: tests/fixtures/**/*.d.ts

About

d.ts generator for javascript

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 94.6%
  • JavaScript 3.0%
  • Python 2.4%