When writing webpack configuration in TypeScript, what typings to use when module.exports is a function?

Viewed 171

I have this in my webpack.config.ts:

import * as webpack from 'webpack'

module.exports = (env, argv): webpack.Configuration => {
  return {};
}

But it’s unclear to me what types I should use for env and argv.

I couldn’t find the answer in Webpack documentation, anywhere on the web or in my code editor suggestion, and I couldn’t make sense of the webpack typing files. The closer I have is the description in the Configuration Types of the webpack documentation, but it’s unclear what the exact type is.

1 Answers

From the webpack bug tracker, I learned that there are no dedicated types defined (at least right now). Instead, one of the correct options is to use these types:

module.exports = (
  env: Record<string, any>,
  argv: Record<string, any>,
): webpack.Configuration => {
  return {};
}
Related