{"id":13657633,"url":"https://github.com/angular/clutz","last_synced_at":"2025-10-06T11:31:08.538Z","repository":{"id":27593739,"uuid":"31076984","full_name":"angular/clutz","owner":"angular","description":"Closure to TypeScript `.d.ts` generator","archived":true,"fork":false,"pushed_at":"2020-10-26T16:14:48.000Z","size":3711,"stargazers_count":162,"open_issues_count":62,"forks_count":60,"subscribers_count":23,"default_branch":"stable","last_synced_at":"2024-09-26T11:03:45.525Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/angular.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-20T17:52:24.000Z","updated_at":"2024-02-26T17:09:39.000Z","dependencies_parsed_at":"2022-09-02T17:30:38.106Z","dependency_job_id":null,"html_url":"https://github.com/angular/clutz","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angular%2Fclutz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angular%2Fclutz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angular%2Fclutz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angular%2Fclutz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/angular","download_url":"https://codeload.github.com/angular/clutz/tar.gz/refs/heads/stable","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219877267,"owners_count":16554853,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T05:00:47.144Z","updated_at":"2025-10-06T11:31:03.129Z","avatar_url":"https://github.com/angular.png","language":"Java","funding_links":[],"categories":["Java (78)"],"sub_categories":[],"readme":"# Clutz - Closure to TypeScript Declarations (`.d.ts`) generator.\n\n\u003e Clutz has been archived, which means the repository is in a read-only state. Clutz will not receive updates, and issues and pull requests will be locked.\n\n\u003e We don’t believe that Clutz satisfies the needs of the open-source community. The use-case it was designed for is very limited, and only works with the full stack of Google TypeScript tooling. Clutz has also proven to be difficult to use: due to the tight integration with Closure Compiler it is only usable when building the latest versions of each. Additionally, many have tried to use it as a general JavaScript to TypeScript migrator and it fails at this. \n\n\u003e We have updated the default branch to be buildable so that existing users may continue using Clutz as-is.\n\n\nThis project uses the\n[Closure Compiler](https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler)\nto parse Closure-style JSDoc type annotations from ES5/ES2015 code, and\ngenerates a suitable TypeScript type definition file (`.d.ts`) for the exported\nAPI.\n\nThe intent is to allow TypeScript code to import libraries written with\nClosure-style type declarations. Having the clutz generated declarations allows\ntype-checking in the TypeScript compiler and IDE tooling (for highlighting\nerrors and type-sensitive auto-complete) as if the imported code was written in\nTypeScript.\n\n## Supported versions\n\nWe lack the resources to make Clutz releases or support multiple versions of\ndependent tools simultaneously. You'll have the most success with Clutz if you\nuse it with:\n\n-   Closure Compiler at HEAD: whatever maven thinks -SNAPSHOT is.\n-   A recent version of TypeScript: the test suite runs against the version of\n    `typescript` in `npm-shrinkwrap.json`, so that is always a good choice.\n\n## Example usage\n\nWe don't offer a binary distribution, so first you need to build from source.\nFrom the root directory run:\n\n```shell\n$ npm install\n$ ./gradlew build installDist # or just \"gradlew\" on Windows\n...\nBUILD SUCCESSFUL\n```\n\nYou can use Clutz from the command line using the wrapper script produced by\nGrade or by executing the JAR file in `build/libs/` yourself. Here is a sample\nexecution:\n\n```shell\n$ PATH=$PATH:./build/install/clutz/bin\n$ clutz path/to/my/source1.js path/to/my/source2.js ...\n        --externs path/to/closure-compiler/externs/es3.js path/to/closure-compiler/externs/es5.js ...\n        -o out.d.ts\n```\n\nThis creates TypeScript type definitions in `out.d.ts` for all the closure types\ndiscovered in the inputs. Symbols which were declared with `goog.provide('x')`\nmay be imported in TypeScript as `import x from 'goog:x';`. For full explanation\nof what TypeScript types are produced for different Closure usages, see the\n`.js` and `.d.ts` files in `src/test/com/google/javascript/clutz`.\n\nWhen compiling TypeScript code that depends on the closure code, include the\n`src/resources/closure.lib.d.ts` file along with `out.d.ts`.\n\nNote that clutz requires that your code can be compiled with Closure Compiler.\nIf you get errors, try reproducing them without clutz, by compiling your code\nwith Closure alone. The arguments for invoking clutz are intentionally similar\nto the arguments for invoking the Closure compiler. You can find the additional\ncompiler flags that clutz passes to Closure Compiler in\n`src/main/java/com/google/javascript/clutz/Options.java`. If the failure is\nreproducible this way, then you have a closure type error in your code (or a bug\nin Closure Compiler).\n\n# Gents - Closure to TypeScript converter\n\nThis repository also hosts `gents` - tool that generates TypeScript code out of\nClosure annotated `.js`. We host it in this repo together with `clutz` because\nthey both wrap Closure Compiler to get the type information. As such `gents`\nshares `clutz` restriction that it only accepts code that is valid well-typed\nClosure JavaScript.\n\nDetails about some specific conversions follow:\n\n### Module Conversion\n\n`gents` converts Closure `goog.module` and `goog.provide` module/namespaces into\nTypeScript modules. On the exporting side, it converts export assignments into\nTypeScript export statements. On the importing side, it converts `goog.require`\nstatements into TypeScript imports. Due to naming issues, this may result in the\nrenaming of the imported symbols.\n\n```javascript {.good}\n// file a.js\ngoog.module('mod.A');\nexports = function(n) { return n; };\n\n// file b.js\ngoog.provide('provided.B');\nprovided.B.val = 4;\n\n// file c.js\ngoog.module('importer.C');\nvar A = goog.require('mod.A');\nvar B = goog.require('provided.B');\n\n/** @type {number} */\nvar num = A(B.val);\n```\n\nIs converted to:\n\n```javascript {.good}\n// file a.ts\nexport const A = function(n) { return n; };\n\n// file b.ts\nexport const val = 4;\n\n// file c.ts\nexport {};\nimport {A} from \"./a\";\nimport * as B from \"./b\";\n\nlet num: number = A(B.val);\n```\n\n### Class Conversion\n\n`gents` converts `@constructor` annotated functions and `goog.defineClass` into\nES6 class declarations. Additionally, it moves all prototype and static\nmethod/field declarations into the class.\n\n```javascript {.good}\n/**\n * @param {number} n\n * @constructor\n */\nfunction A(n) {\n  /** @type {number} */\n  this.num = n;\n}\n\n/** @return {number} */\nA.prototype.foo = function() { return 4; };\n/** @return {boolean} */\nA.bar = function() { return false; };\n/** @type {boolean} */\nA.x = true;\n```\n\nIs converted to:\n\n```javascript {.good}\nclass A {\n  num: number;\n  static x: boolean = true;\n\n  constructor(n: number) {\n    this.num = n;\n  }\n  foo(): number {\n    return 4;\n  }\n  static bar(): boolean {\n    return false;\n  }\n}\n```\n\n### Type Conversion\n\n`gents` converts JSDoc annotated JavaScript into the proper TypeScript\ndeclaration. Note that just like with classes, `gents` only converts explicitly\nannotated types. This is to make sure `gents` doesn't accidentally aggressively\ninfer the types of every variable and generate giant type declarations.\n\n### Known Issues and TODOs\n\n[Github issues](https://github.com/angular/clutz/issues?q=is%3Aopen+is%3Aissue+label%3Agents)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fangular%2Fclutz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fangular%2Fclutz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fangular%2Fclutz/lists"}