{"id":17714505,"url":"https://github.com/sagifogel/typescript-closure-compiler","last_synced_at":"2025-09-12T08:33:43.352Z","repository":{"id":45456093,"uuid":"50288163","full_name":"sagifogel/typescript-closure-compiler","owner":"sagifogel","description":"Patches the TypeScript compiler to generate JSDoc annotations","archived":false,"fork":false,"pushed_at":"2023-10-24T11:06:15.000Z","size":6243,"stargazers_count":82,"open_issues_count":2,"forks_count":8,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-08-16T02:37:25.928Z","etag":null,"topics":["closure-compiler","jsdoc-annotations","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sagifogel.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-01-24T13:11:27.000Z","updated_at":"2025-02-20T00:18:23.000Z","dependencies_parsed_at":"2024-06-18T22:50:22.682Z","dependency_job_id":"f0371e33-5a70-4300-b5ff-d32d085a4195","html_url":"https://github.com/sagifogel/typescript-closure-compiler","commit_stats":{"total_commits":229,"total_committers":3,"mean_commits":76.33333333333333,"dds":0.1353711790393013,"last_synced_commit":"03947a1a8fe872ea509302f1a6fed351d14ee89f"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/sagifogel/typescript-closure-compiler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagifogel%2Ftypescript-closure-compiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagifogel%2Ftypescript-closure-compiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagifogel%2Ftypescript-closure-compiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagifogel%2Ftypescript-closure-compiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sagifogel","download_url":"https://codeload.github.com/sagifogel/typescript-closure-compiler/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagifogel%2Ftypescript-closure-compiler/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271424995,"owners_count":24757382,"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","status":"online","status_checked_at":"2025-08-21T02:00:08.990Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["closure-compiler","jsdoc-annotations","typescript"],"created_at":"2024-10-25T11:15:01.414Z","updated_at":"2025-08-21T04:30:56.630Z","avatar_url":"https://github.com/sagifogel.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TypeScript Closure Compiler\n\nThis patches the TypeScript compiler to generate JSDoc annotations ready for Google Closure Compiler.\u003cbr/\u003e A demo is available online at [http://sagifogel.github.io/typescript-closure-compiler/](http://sagifogel.github.io/typescript-closure-compiler/).\u003cbr/\u003e\nThe current version is compatible with TypeScript 1.8.10.\u003cbr/\u003e\nFor the purposes of clarity each npm package that will be released will match TypeScript\\`s major and minor version.\u003cbr/\u003e\nFor example each version of `typescript-closure-compiler` that is compatible with TypeScript 1.7.5 will be constructed as \n`1.7.x` and each version that is compatible with TypeScript 1.8.10 will be constructed as `1.8.x`.\u003cbr/\u003e\u003cbr/\u003e\n\n## Installing\n\nFor the latest stable version:\n\n```js\nnpm install -g typescript-closure-compiler\n```\n\nIf you work with a specific version of TypeScript (for instance 1.7.5), \u003cbr/\u003eThen you need to install it globally using the @{version} after the `typescript-closure-compiler` name:\u003cbr/\u003e\n```js\nnpm install -g typescript-closure-compiler@1.7.x\n```\n\n## Usage\n\nThe patched version of the TypeScript compiler is available as `tscc` after installing globally with `npm install -g typescript-closure-compiler`. Substitute `tsc` with `tscc` in your build script. Note that the `--module` flag is supported only for the compilation phase (you can write your code using any preferred module system), it won't be present in the output files since the intent is to compile and optimize all code into one big bundle.\u003cbr/\u003e\nAlso the output of the `tscc` will transpile into ECMAScript 5\n\n```js\ntscc app.ts\n```\n\n### Using the gulp task  \n\n`tscc` is a command line compiler much like TypeScript\\`s `tsc` file. \u003cbr/\u003eYou can also choose to compile your code using a [gulp plugin for typescript-closure-compiler](https://www.npmjs.com/package/gulp-typescript-closure-compiler) \n\n## Additional options\n\nThe patched compiler provides couple of additional options that help you to control the output of the closure compiler library.\u003cbr/\u003e\n\n### Export symbols to the global scope\nExporting types to the global scope is done using two additional options.\u003cbr/\u003e\n`--entry` and `--exportAs`. Both options should be explicitly set in order for this feature to work properly.\n\n**entry** - main file that contains all exported types.\u003cbr/\u003e\n**exportAs** - the name of the main symbol that will be exported to the global scope.\u003cbr/\u003e\n\n```js\ntscc app.ts --module commonjs --entry app.ts --exportAs App\n```\n\n### Declaring Extern symbols\nIf you use third party libraries in your code and you don't want Closure Compiler to rename its symbols, you need to declare some externs. Declaring externs is done using additional option `--externs`.\u003cbr/\u003e\nAll you need to do is specify the list of extern files after the `externs` option.\n\n```js\ntscc app.ts --module commonjs --externs externs/app-extern.d.ts...\n```\n\nYou can also specify the files in a `tsconfig.json` file.\u003cbr/\u003e\nuse the `project` option to locate the tsconfig.json file:\u003cbr/\u003e \n```js\ntscc --project [project specific directory]\n```\nand declare the options in the `tsconfig.json` file: \n```js\n{\n  \"compilerOptions\": {\n    \"module\": \"commonjs\"\n  },\n  \"files\": [\n    \"app.ts\"\n  ],\n  \"externs\": [\n    \"externs/app-externs.d.ts\"\n  ]\n}\n``` \n\nyou can also use the `externsOutFile` option in order to emit all extern files to a single file.\n\n```js\ntscc app.ts --module commonjs --externs externs/app-extern.d.ts --externsOutFile externs.js\n```\nor declaring it in the `config.ts` file:\n```js\n{\n  \"compilerOptions\": {\n    \"module\": \"commonjs\",\n    \"externsOutFile\": \"externs.js\"\n  },\n  \"files\": [\n    \"app.ts\"\n  ],\n  \"externs\": [\n    \"externs/app-externs.d.ts\"\n  ]\n}\n``` \n\n### One side enums\nBy default `typescript-closure-compiler` emits bi-directional enums, which means that the key could also be resolved using the value.\n```js\nenum EventType {\n    mouseup = 0,\n    mousedown = 1\n}\n```\nwill be translated to:\n```js\nvar EventType = {\n    mouseup: 0,\n    mousedown: 1,\n    \"0\": \"mouseup\",\n    \"1\": \"mousedown\"\n};\n```\nIn order to resolve the key from the value you can write:\n```js\nconsole.log(EventType[0]); \n```\n\"mouseup\" will be printed\n\nYou can use the `emitOneSideEnums` property to override this behaviour and to just emit one side enums:\n```js\ntscc app.ts --module commonjs --emitOneSideEnums\n```\nNow for the same enum the emitted code will be:\n```js\nvar EventType = {\n    mouseup: 0,\n    mousedown: 1\n};\n```\n\n### experimentalDecorators and ignoreDecoratorsWarning \nIn case you annotate your class/methods/params with decorators without enabling the `experimentalDecorators` option, \n`TypeScript` will emit all the code that enables this feature, but will output a warning message to enable this option.\n```js\nfunction f() {\n    console.log(\"f(): evaluated\");\n    return function (target, propertyKey: string, descriptor: PropertyDescriptor) {\n        console.log(\"f(): called\");\n    } \n}\n\nclass C {\n    @f()\n    method() {}\n}\n```\nThe output will be:\n\u003e  Experimental support for decorators is a feature that is subject to change in a future release.\u003cbr/\u003e\n\u003e  Set the 'experimentalDecorators' option to remove this warning.\n\n`typescript-closure-compiler` changes this behaviour and omits all decorators relevant code when the `experimentalDecorators` is not  enabled, thus ensuring that the generated javascript will not include unnecessary code.\u003cbr/\u003e\nIn addition `typescript-closure-compiler` enables you to use the `ignoreDecoratorsWarning` option in order to ignore the warning message.\u003cbr/\u003e\nThese two options enables you to write your code once using decorations, but to omit the decorations related code using configuration, much like choosing the verbosity of a logger using configuration.\u003cbr/\u003e\u003cbr/\u003e \nA reasonable scenario would be to decorate your class/methods/params with decorators for debug purposes but to omit this code in the final release.\u003cbr/\u003e\nAll you have to do is create two tsconfig.json files one for debug and one for release.\u003cbr/\u003e\nThe release file should include the `ignoreDecoratorsWarning`.\nThe debug file should include the `experimentalDecorators`.\n\n#### release\n```js\n{\n  \"compilerOptions\": {\n    \"ignoreDecoratorsWarning\": true\n  }\n  \"files\": [\n  ]\n}\n``` \n#### debug\n```js\n{\n  \"compilerOptions\": {\n    \"experimentalDecorators\": true\n  }\n  \"files\": [\n  ]\n}\n``` \n\n### Usage Examples\n\nSee an example of `typescript-closure-compiler` using `gulp-typescript-closure-compiler` plugin in the [TSFunq](https://github.com/sagifogel/TSFunq) project.\n\n## Building\n\nThe build tool that was chosen for this project is [Jake](http://jakejs.com/), for compatibility reasons with TypeScript`s build system.\u003cbr/\u003e\n\n```\ngit clone https://github.com/sagifogel/typescript-closure-compiler.git\n```\n\nInstall Jake tools and the dev dependencies of `typescript-closure-compiler`\n\n```\nnpm install -g jake\nnpm install\n```\n\nClone the submodule \n```\ncd .\\TypeScript\ngit submodule update --init\n```\n\nNavigate to the `TypeScript` folder and install its dependencies\n\n```\nnpm install\n```\n\nReturn to the folder of `typescript-closure-compiler` and execute the build\n\n```\njake build\n```\n \n## License\n\nLike the TypeScript compiler itself, this code is licensed under the [Apache License 2.0](http://typescript.codeplex.com/license).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsagifogel%2Ftypescript-closure-compiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsagifogel%2Ftypescript-closure-compiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsagifogel%2Ftypescript-closure-compiler/lists"}