如何在Karma-Webpack中使用Node Typescript类型

时间:2016-12-19 17:55:03

标签: node.js typescript webpack karma-webpack

我已将Webpack配置为在Karma中转换我的TS文件。我还包括Node和CoreJS类型。但是,当我尝试运行我的测试时,我得到了......

var db = require(path.resolve('sequelize'));

exports.runQueries= function (req, res, queries) {

  // queries os an array

  var runQueries = function(query){
    return new Promise(resolve => db.sequelize.query(query, { type: db.Sequelize.QueryTypes.SELECT }));
  };

  var actions = queries.map(runQueries);

  Promise.all(actions).then(function(data){
    res.send(data);
  });

};

我尝试使用ERROR in ./test/karma/test.bundle.ts (18,30): error TS2339: Property 'context' does not exist on type 'NodeRequire'. 添加webpack-env,但这会给我带来更多错误。

npm install --save-dev @types/webpack-env

我的Karma配置看起来像这样......

ERROR in /.../node_modules/@types/webpack-env/index.d.ts
(183,13): error TS2403: Subsequent variable declarations must have the same type.  Variable 'require' must be of type 'NodeRequire', but here has type 'RequireFunction'.

ERROR in /.../node_modules/@types/webpack-env/index.d.ts
(232,13): error TS2403: Subsequent variable declarations must have the same type.  Variable 'module' must be of type 'NodeModule', but here has type 'Module'.

ERROR in ./test/karma/test.bundle.ts
(18,30): error TS2339: Property 'context' does not exist on type 'NodeRequire'.

版本

webpack 1.14.0,node v6.9.2,Typescript 2.1.4

0 个答案:

没有答案