Skip to content
This repository has been archived by the owner on Oct 29, 2023. It is now read-only.
/ closure-ts Public archive

Generates TypeScript declarations(d.ts) from Closure Library JSDoc annotations

Notifications You must be signed in to change notification settings

teppeis/closure-ts

Repository files navigation

closure-ts

npm Version Node.js Version Support Build Status Dependency Status License

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 @param and @return
  • Namespace to TypeScript module
  • Classes (@constructor and @extends)
  • Enum with @enum to TypeScrip type alias and variables
  • Convert * and ? to any
  • Generic type like Array<number>
  • Generic classes and function with @template
  • Union type
  • Record type
  • Rest parameters in @param and FunctionType
  • Optional parameters
  • Exclude @private definitions
  • Convert @typedef to type
  • Convert @record to interface
  • Convert Object<string, Foo> to {[index: string]: Foo}
  • Ignore features TypeScript doesn't have
    • @this, this: and new: of function type
    • Nullable, Non-Nullable

TODO

  • @lends
  • Dependencies of Closure Library files
  • One stop build system with Grunt or Gulp

About

Generates TypeScript declarations(d.ts) from Closure Library JSDoc annotations

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy