/closure-tcljs

Generates core.typed annotations from Closure Library JSDoc annotations.

Primary LanguageJavaScript

closure-tcljs

Generates core.typed annotation files from Closure Library JSDoc annotations.

WIP

Example

From this JavaScript code with annotations,

/**
 * @typedef {Array|NodeList|Arguments|{length: number}}
 */
goog.array.ArrayLike;


/**
 * Returns the last element in an array without removing it.
 * @param {Array.<T>|goog.array.ArrayLike} array The array.
 * @return {T} Last item in array.
 * @template T
 */
goog.array.peek = function(array) {
  return array[array.length - 1];
};

closure-tcljs should generates this declaration file (d.clj)

(ns goog.array)

(def-alias ArrayLike (U
    (Array any)
    NodeList
    Arguments
    (HMap :mandatory {:length number})
))

(ann peek (All [T] [(U (Array T) goog.array.ArrayLike) -> T]))

Usage

$ bin/closure-tcljs some-jsdoced-code.js
$ ls
some-jsdoced-code.d.clj
some-jsdoced-code.js

Project status

WIP. Not yet usable from core.typed

Implemented

  • Variable with @type
  • Function with @param and @return
  • Namespace to tcljs ns
  • Classes (@constructor and @extends) to tcljs datatype
  • Generic type like (Array number)
  • Generic classes and function with @template
  • Union type
  • Record type
  • Rest parameters in @param and FunctionType
  • Exclude @private definitions
  • @typedef (partialy)
  • Derive annotations for constructor functions such as Number. from corresponding classes' constructor
  • Ignore features core.typed doesn't have
    • @this, new of function type
    • Nullable, Non-Nullable

TODO

  • Interfaces
  • @lends
  • Enum with @enum to TypeScript Interface
  • Dependencies of Closure Library files
  • Arity overloading with IFn (Optional Parameters)
  • One stop build system with Grunt or Gulp

LICENSE

MIT (original repo doesn't have LICENCE.md but package.json says it's MIT)

TODO: Add LICENSE.md after confirming w/ teppeis