Tsickle: TypeScript to Closure Translator

0.46.3 · abandoned · verified Tue Apr 21

Tsickle is a TypeScript transpiler designed to convert TypeScript code into JavaScript with Closure Compiler-compatible JSDoc annotations and module formats (`goog.module`). It serves as an intermediate step in build pipelines that leverage Closure Compiler for advanced optimization and minification, particularly within large-scale applications like those developed by Google and Angular. The current stable version is 0.46.3, and its release cadence is irregular, tied to Angular's development and internal Google needs. Key differentiators include its specialized handling of TypeScript types for Closure's type system, conversion of ES6 modules to `goog.module`, and generation of externs.js from TypeScript definition files, making TypeScript projects amenable to the unique optimization strategies of Closure Compiler. It is explicitly noted as a library intended for integration into larger build systems rather than direct end-user application development, often requiring downstream compatibility with Closure's specific module and type conventions.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to use the Tsickle CLI to transpile a simple TypeScript project, generating Closure-annotated JavaScript output in the `dist` directory. This setup includes a `tsconfig.json` and a `package.json` script for execution.

{
  "name": "tsickle-demo",
  "version": "1.0.0",
  "scripts": {
    "build:tsickle": "npx tsickle -p tsconfig.json"
  },
  "devDependencies": {
    "tsickle": "^0.46.3",
    "typescript": "~4.7.2"
  }
}
// tsconfig.json
{
  "compilerOptions": {
    "target": "es2017",
    "module": "esnext",
    "outDir": "dist",
    "declaration": true,
    "strict": true,
    "lib": ["es2017"],
    "allowJs": true
  },
  "include": ["src/**/*.ts"]
}
// src/greeter.ts
/**
 * @fileoverview A simple class to demonstrate Tsickle conversion.
 */
export class Greeter {
  /** @type {string} */
  private readonly name: string;

  /**
   * @param {string} name The name to greet.
   */
  constructor(name: string) {
    this.name = name;
  }

  /**
   * Generates a greeting message.
   * @return {string} The greeting.
   */
  greet(): string {
    return `Hello, ${this.name}!`;
  }
}

// To run this example:
// 1. Create the files above in your project root.
// 2. Run `npm install`
// 3. Run `npm run build:tsickle`
// This will output Closure-annotated JavaScript to the `dist` directory.

view raw JSON →