webpack-contrib/terser-webpack-plugin

type error after upgrade from 5.2.0 to 5.3.9

GiladShoham opened this issue · 1 comments

Bug report

Actual Behavior

Getting a type error for this configuration:

new TerserPlugin({
    minify: TerserPlugin.esbuildMinify,
    terserOptions: {
      minify: false,
      minifyWhitespace: true,
      minifyIdentifiers: false,
      minifySyntax: true,
    },
  });

error:

Type '{ minify: false; minifyWhitespace: true; minifyIdentifiers: false; minifySyntax: true; }' is not assignable to type 'MinimizerOptions<MinifyOptions>'.
  Object literal may only specify known properties, and 'minify' does not exist in type 'MinimizerOptions<MinifyOptions>'.ts(2322)
index.d.ts(120, 7): The expected type comes from property 'terserOptions' which is declared here on type 'BasePluginOptions & { minify?: MinimizerImplementation<MinifyOptions>; terserOptions?: MinimizerOptions<MinifyOptions>; }'

Expected Behavior

This config should be valid according to the docs - here

It used to work with terser v5.2.0, but stopped working when upgraded to 5.3.9.

The last working version is 5.2.1, once upgraded to 5.2.2 it start breaking.
I believe it's a result of this commit

How Do We Reproduce?

Reproduce repo

Please paste the results of npx webpack-cli info here, and mention other relevant information

System:
    OS: macOS 13.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 145.31 MB / 64.00 GB
  Binaries:
    Node: 18.16.1 - ~/.nvm/versions/node/v18.16.1/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.16.1/bin/yarn
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.1/bin/npm
  Browsers:
    Chrome: 119.0.6045.105
    Safari: 16.2

Update:
Seems that I need to add

import type { TransformOptions as EsbuildOptions } from "esbuild";

new TerserPlugin<EsbuildOptions>({....})