Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@lang/rollup-plugin-dts

Swatinem3.1kLGPL-3.02.0.2TypeScript support: included

An experiment to generate .d.ts rollup files

rollup-plugin, typescript, dts, @types

readme

rollup-plugin-dts

Build Status Coverage Status

This is a plugin that lets you roll-up your .d.ts definition files.

Usage

Install the package from npm:

$ npm install --save-dev rollup-plugin-dts

Add it to your rollup.config.js:

import dts from "rollup-plugin-dts";

const config = [
  // …
  {
    input: "./my-input/index.d.ts",
    output: [{ file: "dist/my-library.d.ts", format: "es" }],
    plugins: [dts()],
  },
];

export default config;

And then instruct typescript where to find your definitions inside your package.json:

  "types": "dist/my-library.d.ts",

NOTE that the plugin will automatically mark any external library (@types for example) as external, so those will be excluded from bundling.

What to expect

While this plugin is fairly complete, it does not support all imaginable use-cases. In particular, the plugin works best with already existing .d.ts files generated by the typescript compiler from idiomatic code.

Working with .ts(x) or even .js(x) (when setting allowJs: true) does work, but is not recommended.

The plugin does its own import resolution through the typescript compiler, and usage together with other resolution plugins, such as node-resolve can lead to errors and is not recommended.

All external dependencies from node_modules are automatically excluded from bundling. This can be overridden using the respectExternal setting, but it is generally not recommended. While rollup of external @types generally works, it is not recommended.

Why?

Well, ideally TypeScript should just do all this itself, and it even has a proposal to do that. But there hasn’t been any progress in ~3 years.

Some projects, like rollup itself go the route of completely separating their public interfaces in a separate file.

Alternatives

See some discussions about some of these projects and their tradeoffs.

How does it work

License

The code is licensed under the copyleft LGPL-3.0. I have no intention to license this under any non-copyleft license.

changelog

Changelog

2.0.1

** Fixes**:

  • When using code-splitting with multiple input files, type references directives will be correctly attached only to the output files that reference them.

2.0.0

Compatibility Notice:

This release targets TypeScript 4.1 and support for previous versions was dropped.

Features:

  • The plugin gained a new pre-processing step that added support for unnamed export default declarations and splitting up variable declarations that were previously rejected.

1.4.14

Released on 2020-11-14

  • Better support for monorepos.

Features, fixes and improvements in this release have been contributed by:

1.4.13

Released on 2020-09-05

Fixes:

  • Correctly update ranges when merging declarations.

1.4.12

Released on 2020-08-23

Fixes:

  • Add support for variadic tuple types and named tuple members that were added in typescript@4.

Thank you:

Features, fixes and improvements in this release have been contributed by:

1.4.11

Released on 2020-08-21

Fixes:

  • Make the plugin compatible with typescript 4.

Thank you:

Features, fixes and improvements in this release have been contributed by:

1.4.10

Released on 2020-08-05

Fixes:

  • Correctly add declare keyword to any variable statement.

1.4.9

Released on 2020-07-21

Fixes:

  • Correctly resolve type-arguments of inline imports.

1.4.8

Released on 2020-07-12

Fixes:

  • Make allowJs work correctly.
  • Make type-aliases and generics work in namespace exports.

Thank you:

Features, fixes and improvements in this release have been contributed by:

1.4.7 2020-05-22

  • Fix AST incompatibility with rollup.
  • Override noEmit option to correctly generate intermediate artifacts.

1.4.6 2020-05-17

  • Ignore/Remove EmptyStatements.
  • Strip file extensions for import/re-export statements when using multiple entry points.

1.4.4 2020-05-17

  • Add support for ImportEquals (import foo = require("bar");).
  • Work around rollup not stripping the complete .d.ts extension for entryFileNames [name] placeholder.

1.4.3 2020-05-13

  • Fixes to work with newest rollup.

1.4.2 2020-05-10

  • Reorder same-named declarations.

1.4.1 2020-05-08

  • Add support for export * as foo declarations.

1.4.0 2020-04-11

  • Fix renaming of MemberExpressions.
  • Make modifier rewriting more resilient to missing declare modifier.
  • Support TS path-mapping via compilerOptions.

1.3.0 2020-03-11

  • support rollup > 2
  • correctly output declare global and module "foo" declarations.

1.2.1 2020-01-26

  • try to correctly resolve .d.ts files when building .ts files
  • fix using literals for computed properties
  • ignore export as namespace declarations

1.2.0 2020-01-06

  • add a new respectExternal option, which will not exclude all external dependencies from bundling, but rather respect the external rollup option.

1.1.13 2019-12-07

  • add support for optional type nodes

1.1.12 2019-11-06

  • add support for getters / setters as generated by TypeScript 3.7

1.1.11 2019-11-05

  • fix generic type parameters of inline-imports

1.1.10 2019-10-03

  • fix leading comments being removed from rendered chunks
  • fix issues with multiple inline-imports

1.1.9 2019-10-03

  • support RestType Nodes

1.1.8 2019-09-30

1.1.7 2019-09-09

1.1.6 2019-07-31

  • further improve computed property handling
  • add support for bigint type

1.1.5 2019-07-01

  • properly handle computed properties

1.1.4 2019-06-21

  • fix issues around default exports and overrides

1.1.3 2019-06-21

  • fix duplicated definitions when having circular imports on windows

1.1.2 2019-06-18

  • normalize directory separators on windows

1.1.1 2019-06-16

  • correctly preserve tripleslash reference directives

1.1.0 2019-06-07

  • Re-add support for directly using .ts files.
  • Fix type parameters with extends constraints.

1.0.0 2019-06-05

  • This release focuses on working with pre-generated .d.ts files.
  • Thus, this release drops support for transpiling .ts -> .js.
  • Support for namespace re-exports and dynamic imports of namespaces.