closure-ts
closure-ts copied to clipboard
Generates TypeScript declarations(d.ts) from Closure Library JSDoc annotations
closure-ts
Generates TypeScript declaration files (.d.ts) from Closure Library JSDoc annotations.
The result is closure-library.d.ts.
Example
From this JavaScript code with annotations,
/**
* Truncates a string to a certain length.
* @param {string} str
* @param {number} chars
* @param {boolean=} opt_protectEscapedCharacters
* @return {string}
*/
goog.string.truncate = function(str, chars, opt_protectEscapedCharacters) {
// ...
};
closure-ts generates this declaration file (.d.ts).
declare module goog.string {
/**
* Truncates a string to a certain length.
* @param {string} str
* @param {number} chars
* @param {boolean=} opt_protectEscapedCharacters
* @return {string}
*/
function truncate(str: string, chars: number, opt_protectEscapedCharacters?: boolean): string;
}
Usage
$ closurets some-jsdoced-code.js
$ ls
some-jsdoced-code.d.ts
some-jsdoced-code.js
Project status
Just PoC
Implemented
- Variable with
@type - Function with
@paramand@return - Namespace to TypeScript
module - Classes (
@constructorand@extends) - Enum with
@enumto TypeScrip type alias and variables - Convert
*and?toany - Generic type like
Array<number> - Generic classes and function with
@template - Union type
- Record type
- Rest parameters in
@paramand FunctionType - Optional parameters
- Exclude
@privatedefinitions - Convert
@typedeftotype - Convert
@recordtointerface - Convert
Object<string, Foo>to{[index: string]: Foo} - Ignore features TypeScript doesn't have
@this,this:andnew:of function type- Nullable, Non-Nullable
TODO
@lends- Dependencies of Closure Library files
- One stop build system with Grunt or Gulp