TS2304:在 Webpack/Angular 2 中找不到名称“描述”

Rob*_*uie 4 typescript webpack angular

我已经广泛搜索了这个问题,但我发现没有任何东西可以解决它。我正在尝试使用 webpack 运行单个 jasmine 测试。我试图按照 Angular 网站上的教程进行操作,但它......不是真的正确或完整。

这是我迄今为止尝试过的:

  • 已安装的 Jasmine 类型,它们存在于我的 node_modules/@types/jasmine
  • 添加"types": ["jasmine"]到我的 tsconfig.json 即使您不必在 Typescript 2.0.X 中这样做
  • 添加"typeRoots": ["./node_modules/@types"]到我的 tsconfig.json 即使您不必在 Typescript 2.0.X 中这样做
  • 添加import {} from 'jasmine';到我的单元测试中,如下所述:Angular 2 单元测试:找不到名称“描述”

那时我觉得我离基地很远,这里必须有其他事情发生。我正在使用 awesome-typescript-loader,也许它无法弄清楚类型?

我使用的是 2.0.9 版本的 typescript,我的配置文件如下:

webpack.test.ts

var webpack = require('webpack');
var helpers = require('./helpers');

module.exports = {
  devtool: 'inline-source-map',

  resolve: {
    extensions: ['.ts', '.js']
  },

  module: {
    rules: [
      {
        test: /\.ts$/,
        loaders: [
          {
            loader: 'awesome-typescript-loader',
            options: { configFileName: helpers.root('tsconfig.json') }
          } , 'angular2-template-loader'
        ]
      },
      {
        test: /\.html$/,
        loader: 'html-loader'

      },
      {
        test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
        loader: 'null-loader'
      },
      {
        test: /\.css$/,
        exclude: helpers.root('src', 'app'),
        loader: 'null-loader'
      },
      {
        test: /\.css$/,
        include: helpers.root('src', 'app'),
        loader: 'raw-loader'
      }
    ]
  },

  plugins: [
    new webpack.ContextReplacementPlugin(
      // The (\\|\/) piece accounts for path separators in *nix and Windows
      /angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
      helpers.root('./src'), // location of your src
      {} // a map of your routes
    )
  ]
}
Run Code Online (Sandbox Code Playgroud)

配置文件

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "es2015",
      "dom"
    ],
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "target": "es5"
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ],
  "compileOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}
Run Code Online (Sandbox Code Playgroud)

编辑:我用来运行测试的命令: karma start ./config/karma.conf.js --single-run

Rob*_*uie 5

呃……我找到了。正如我在我的帖子中所说,我使用的是 typescript 2.0.9,但最新版本的 @types/jasmine 使用的keyof是 typescript 2.1 的一个特性......:/

我将@types/jasmine 恢复到 2.5.41,一切都很好。

  • Angular 是一个纸牌屋 (2认同)