talira

rollup-plugin-typescript2

Rollup plugin that compiles TypeScript and reports its type errors

open sourceMITfree

rollup-plugin-typescript2 is a Rollup plugin that compiles TypeScript with the TypeScript compiler itself and prints its syntactic and semantic diagnostics during the build, which the original rollup-plugin-typescript didn't. It's a rewrite of that plugin, a little slower, and takes its compiler options and file list from tsconfig.json, with options to point at another tsconfig or override settings. It writes declaration files and declaration maps, keeps a cache between builds, and can run beside a transpiling plugin such as Babel, esbuild or SWC to do only type-checking and declarations.

Problems it solves

  • see TypeScript type errors when I bundle my library with Rollup
  • build a TypeScript library with Rollup and get .d.ts declaration files
  • my Rollup TypeScript build passes even though the code has type errors

Features

  • Prints TypeScript's syntactic and semantic errors during a Rollup build
  • Uses the compiler options and files from tsconfig.json, with overrides
  • Emits declaration files and declaration maps
  • Caches compilation between builds
  • Can type-check and emit declarations while another plugin transpiles
  • Works in Rollup's watch mode

Limitations

  • Slower than the original rollup-plugin-typescript, since it runs the full type checker1
  • Changes to type-only imports and ambient types don't trigger a rebuild in watch mode1

Alternatives

The same job

These do what rollup-plugin-typescript2 does.

  1. rollup-plugin-dts Bundle TypeScript .d.ts declaration files with Rollup
  2. tsdown Library bundler for TypeScript and JavaScript, built on Rolldown
  3. unplugin-dts Generate .d.ts declaration files from TypeScript or Vue sources in your bundler
  4. tsup Zero-config bundler for TypeScript libraries, powered by esbuild
  5. Rollup ES module bundler for JavaScript libraries and apps, with tree shaking
  6. ts-loader The TypeScript loader for webpack: compile .ts and .tsx files as part of a webpack build

Compare rollup-plugin-typescript2 with the top 3