webpack-contrib/image-minimizer-webpack-plugin

Typescript types are not correct

awdr74100 opened this issue · 1 comments

Bug report

Thank you for your help in many places!!

This time it seems that all minimizer have some type error.

Actual Behavior

The main code is copied from README.md.

import { Configuration } from 'webpack';
import { merge } from 'webpack-merge';
import ImageMinimizerPlugin from 'image-minimizer-webpack-plugin';
import baseWebpackConfig from './webpack.base.conf';

const config = merge<Configuration>(baseWebpackConfig, {
  mode: 'production',
  devtool: 'source-map',
  optimization: {
    minimize: true,
    minimizer: [
      '...',
      new ImageMinimizerPlugin({
        minimizer: {
          // Implementation
          implementation: ImageMinimizerPlugin.sharpMinify,
          // Options
          options: {
            encodeOptions: {
              jpeg: {
                quality: 90,
              },
            },
          },
        },
      }),
    ],
  },
});

export default config;
Type '{ implementation: <T>(original: ImageMinimizerPlugin.WorkerResult, minimizerOptions: T) => Promise<ImageMinimizerPlugin.WorkerResult | null>; options: { ...; }; }' is not assignable to type 'Minimizer<unknown> | Minimizer<unknown>[] | undefined'.
  Types of property 'implementation' are incompatible.
    Type '<T>(original: WorkerResult, minimizerOptions: T) => Promise<WorkerResult | null>' is not assignable to type 'TransformerFunction<unknown>'.
      Type '<T>(original: WorkerResult, minimizerOptions: T) => Promise<WorkerResult | null>' is not assignable to type 'BasicTransformerImplementation<unknown>'.
        Type 'Promise<WorkerResult | null>' is not assignable to type 'Promise<WorkerResult>'.
          Type 'WorkerResult | null' is not assignable to type 'WorkerResult'.
            Type 'null' is not assignable to type 'WorkerResult'.

Expected Behavior

It should work just like v3.3.1.

How Do We Reproduce?

Write the any minimizer example provided in README.md through the webpack.config.ts configuration file.

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

  System:
    OS: Windows 10 10.0.22000
    CPU: (12) x64 Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
    Memory: 6.49 GB / 15.92 GB
  Binaries:
    Node: 16.17.0 - ~\AppData\Local\fnm_multishells\25588_1662972884261\node.EXE
    Yarn: 1.22.19 - ~\AppData\Local\fnm_multishells\25588_1662972884261\yarn.CMD
    npm: 8.19.1 - ~\AppData\Local\fnm_multishells\25588_1662972884261\npm.CMD
  Browsers:
    Edge: Spartan (44.22000.120.0), Chromium (105.0.1343.33)
    Internet Explorer: 11.0.22000.120
  Packages:
    copy-webpack-plugin: ^11.0.0 => 11.0.0
    css-loader: ^6.7.1 => 6.7.1
    css-minimizer-webpack-plugin: ^4.1.0 => 4.1.0
    eslint-import-resolver-webpack: ^0.13.2 => 0.13.2
    eslint-webpack-plugin: ^3.2.0 => 3.2.0
    fork-ts-checker-webpack-plugin: ^7.2.13 => 7.2.13
    html-webpack-plugin: ^5.5.0 => 5.5.0
    image-minimizer-webpack-plugin: ^3.4.0 => 3.4.0
    postcss-loader: ^7.0.1 => 7.0.1
    style-loader: ^3.3.1 => 3.3.1
    stylelint-webpack-plugin: ^3.3.0 => 3.3.0
    swc-loader: ^0.2.3 => 0.2.3
    terser-webpack-plugin: ^5.3.6 => 5.3.6
    tsconfig-paths-webpack-plugin: ^4.0.0 => 4.0.0
    webpack: ^5.74.0 => 5.74.0
    webpack-cli: ^4.10.0 => 4.10.0
    webpack-dev-server: ^4.11.0 => 4.11.0
    webpack-merge: ^5.8.0 => 5.8.0