簡體   English   中英

如何在TypeScript 2.1.4中使TS2354錯誤消息靜音?

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

我收到錯誤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.

主要

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中修復。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM