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

Type definition BasePluginOptions property test should use Rules, not Rule #378

Closed
Skarbo opened this issue Feb 27, 2024 · 0 comments · Fixed by #379
Closed

Type definition BasePluginOptions property test should use Rules, not Rule #378

Skarbo opened this issue Feb 27, 2024 · 0 comments · Fixed by #379

Comments

@Skarbo
Copy link

Skarbo commented Feb 27, 2024

Bug report

Type definition BasePluginOptions has the wrong type definition Rule for properties test, include and exclude.

/** @typedef {RegExp | string} Rule */
/** @typedef {Rule[] | Rule} Rules */

/**
 * @template T
 * @typedef {Object} BasePluginOptions
 * @property {Rule} [test]
 * @property {Rule} [include]
 * @property {Rule} [exclude]
 * ...
 */

According to the documentation

type test = string | RegExp | Array<string | RegExp>;

the properties should be defined as Rules:

/**
 * @template T
 * @typedef {Object} BasePluginOptions
 * @property {Rules} [test]
 * @property {Rules} [include]
 * @property {Rules} [exclude]
 * ...
 */

Actual Behavior

When passing array of RegExp as test property in CompressionPlugin constructor, TypeScript will be unable to compile when running Webpack script with TypeScript:

error TS2322: Type 'RegExp[]' is not assignable to type 'Rule'

Expected Behavior

Expect no TypeScript errors when running Webpack script with TypeScript.

How Do We Reproduce?

// my-script.ts
const compressionPlugin = new CompressionPlugin({
  test: [ /foo/, /bar/ ],
});
ts-node my-script.ts

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

System:
    OS: macOS 13.6.3
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 6.69 GB / 32.00 GB
  Binaries:
    Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
  Browsers:
    Chrome: 121.0.6167.184
    Safari: 16.6

"compression-webpack-plugin": "^11.0.0",
"webpack": "^5.90.3",
"ts-node": "^10.9.2",
"typescript": "^5.3.3",
@Skarbo Skarbo changed the title Type definition BasePluginOptions property test should use Rules, not Rule Type definition BasePluginOptions property test should use Rules, not Rule Feb 27, 2024
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

Successfully merging a pull request may close this issue.

1 participant