Giter VIP home page Giter VIP logo

clutz's Introduction

clutz - Closure to .d.ts generator.

Build Status

This project uses the Closure Compiler to parse Closure-style JSDoc type annotations from ES5/ES2015 code, and generates a suitable TypeScript type definition file (.d.ts) for the exported API.

The intent is to allow TypeScript code to re-use libraries written with Closure-style type declarations, and still benefit from type checking in the TypeScript compiler and IDE tooling for highlighting errors and type-sensitive auto-complete.

Example usage

We don't offer a binary distribution, so first you need to build:

$ gradle build installDist
...
BUILD SUCCESSFUL

You can use Clutz as a library from a Java based build, or execute the wrapper script produced by Gradle:

$ PATH=$PATH:./build/install/clutz/bin
$ clutz --externs src/resources/es6_min.js -o out.d.ts path/to/my/sources.js

This creates TypeScript type definitions in out.d.ts for all the closure types discovered in the inputs. Symbols which were declared with goog.provide('x') may be imported as import x from 'goog:x';. For full explanation of what TypeScript types are produced for different Closure usages, see the .js and .d.ts files in src/test/com/google/javascript/clutz.

When compiling TypeScript code that depends on the closure code, include the src/resources/closure.lib.d.ts along with out.d.ts.

Note that clutz requires that your code can be compiled with Closure Compiler. If you get errors, try reproducing them without clutz, just compiling your code with Closure. You can find the options we pass to Closure Compiler in src/main/java/com/google/javascript/clutz/Options.java. If the failure is reproducible this way, then you have a mistake in your code (or a bug in Closure Compiler).

Supported Version of TypeScript

Clutz produces declaration files that are guaranteed to be accepted by a version of TypeScript newer than ac6224d6. The current test suite runs against typescript@next, so that is always a good choice.

clutz's People

Contributors

alexeagle avatar gmoothart avatar jdramaix avatar jjudd avatar lambertjamesd avatar matrixfrog avatar mprobst avatar naomiblack avatar obsc avatar rehmsen avatar rictic avatar rkirov avatar tadeegan avatar

Stargazers

 avatar

Watchers

 avatar  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.