Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@rollup/plugin-typescript] Generate .d.cts files from entryFilenames #1833

Open
drwpow opened this issue Jan 8, 2025 · 0 comments
Open

Comments

@drwpow
Copy link

drwpow commented Jan 8, 2025

  • Rollup Plugin Name: @rollup/plugin-typescript
  • Rollup Plugin Version: *

Feature Use Case

@rollup/plugin-typescript can be used to generate dual CJS + ESM builds, and it correctly generates *.cjs files using entryFilenames. However, for .cjs files, TypeScript requires a .d.cts matching extension. But this plugin will always output at *.d.ts, no matter the settings.

This means when you have a dual CJS + ESM build, you should be getting 2 copies of declarations, but one will always overwrite the other. Yes, the contents are identical. Yes, TypeScript should just figure it out. But TypeScript has chosen to require 1 definition to 1 file, always, which means .cjs files are untyped unless explicit .d.cts definitions exist.

Same for .mjs—if requested, those need .d.mts files as well, if using that extension.

Feature Proposal

import ts from '@rollup/plugin-typescript';

export default {
  input: 'src/index.ts',
  plugins: [ts({
    compilerOptions: {
      declaration: true
    }
  })],
  output: [
    {
      dir: './dist/',
      format: 'cjs',
      preserveModules: true,
      sourcemap: true,
      entryFileNames: '[name].cjs'
    }
  ],
};

Given this Rollup config, this should produce *.d.cts declarations. This may be a breaking change for some folks, but would satisfy TypeScript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant