如何在TypeScript 2.1.4中使TS2354错误消息静音?

时间:2016-12-13 20:00:54

标签: typescript webpack-2 ts-loader

我收到错误TS2354:此语法需要导入的帮助程序,但模块' tslib'在我的webpack 2版本中使用TypeScript 2.1的新importHelpers选项无法找到。。 捆绑似乎按预期构建,但错误消息令人不安。 谁能指出我在这里做错了什么?或者每个错误rxjs\Subject.d.ts是否存在问题(提到的行(Subject.d.ts:9,43)确实使用了无辜的extends关键字)?

ts-loader: Using typescript@2.1.4 and C:Repro\stuff\tsconfig.json
Hash: f24da06626836e4fc997
Version: webpack 2.1.0-beta.28
Time: 4256ms
Asset     Size  Chunks             Chunk Names
app.js  3.01 kB       0  [emitted]  app
  [1] ./src/main.ts 372 bytes {0} [built]
    + 1 hidden modules

ERROR in C:Repro\stuff\node_modules\rxjs\Subject.d.ts
(9,43): error TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.

main.ts

import { Observable } from "rxjs";

Observable.timer(3000, 5000)
  .timeInterval()
  .subscribe((interval) => console.log(interval));

的package.json

{
  "name": "stuff",
  "version": "1.0.0",
  "scripts": {
    "build": "webpack"
  },
  "devDependencies": {
    "@types/core-js": "^0.9.35",
    "ts-loader": "^1.3.2",
    "typescript": "^2.1.4",
    "webpack": "^2.1.0-beta.25"
  },
  "dependencies": {
    "rxjs": "^5.0.1",
    "tslib": "^1.2.0"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "importHelpers": true,
    "target": "es5",
    "noEmitHelpers": true
  }
}

webpack.config.js

module.exports = {
  name: 'server',
  target: 'node',
  entry: { 'app': './src/main.ts' },
  output: { path: './bin/', publicPath: 'bin/', filename: '[name].js' },
  externals: { rxjs: 'commonjs rxjs' },
  module: { rules: [{ test: /\.ts$/, loader: 'ts-loader' }], },
  resolve: { extensions: ['.ts'] }
};

1 个答案:

答案 0 :(得分:0)

看起来这是在this typescript issue下跟踪的,应在TypeScript 2.1.5

中修复