【问题标题】:When writing webpack configuration in TypeScript, what typings to use when module.exports is a function?在 TypeScript 中编写 webpack 配置时,当 module.exports 是一个函数时使用什么类型?
【发布时间】:2022-01-09 05:01:41
【问题描述】:

我的webpack.config.ts有这个:

import * as webpack from 'webpack'

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

但我不清楚应该为 envargv 使用什么类型。

我在 Webpack 文档、网络上的任何地方或我的代码编辑器建议中都找不到答案,而且我无法理解 webpack 输入文件。越接近the Configuration Types of the webpack documentation中的描述,具体是什么类型就不清楚了。

【问题讨论】:

    标签: typescript webpack typescript-generics


    【解决方案1】:

    webpack bug tracker,我了解到没有定义专用类型(至少现在是这样)。相反,正确的选择之一是使用这些类型:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-06-15
      • 2018-10-31
      • 2017-10-22
      • 2021-09-26
      • 2015-02-08
      • 2022-11-11
      • 2021-03-19
      相关资源
      最近更新 更多