简体   繁体   中英

How can I silence the TS2354 error message in TypeScript 2.1.4?

I am getting error TS2354: This syntax requires an imported helper but module 'tslib' cannot be found. on my webpack 2 build using the new importHelpers option of TypeScript 2.1. The bundle seems to build as expected but the error message is troubling. Can anyone point out what I'm doing wrong here? Or is it a problem with rxjs\\Subject.d.ts per the error (that mentioned line (Subject.d.ts:9,43) does use and innocent extends keyword)?

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'] }
};

看起来在此打字稿问题下已得到跟踪, 该问题应在TypeScript 2.1.5中修复。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM