Code Monkey home page Code Monkey logo

closure-ts's Introduction

closure-ts Build Status

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
  • Enum with @enum to TypeScript Interface
  • Namespace to TypeScript module
  • Classes (@constructor and @extends)
  • Convert * to any
  • Generic type like Array<number>
  • Generic classes and function with @template
  • Union type (partialy)
  • Record type
  • Rest parameters in @param and FunctionType
  • Optional parameters
  • Exclude @private definitions
  • @typedef (partialy)
  • Ignore features TypeScript doesn't have
    • @this, new of function type
    • Nullable, Non-Nullable
    • Object.<string, Some>

TODO

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

closure-ts's People

Contributors

teppeis avatar

Watchers

Tony Lee avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.