语义错误为Angular 2编写NgMatchers打字脚本

Semantic errors typescript NgMatchers for Angular 2

本文关键字:NgMatchers 脚本 编写 错误 Angular 语义      更新时间:2023-09-26

我正试图用Gulp和jasmine(在看到这个例子之后)建立一个Angular 2项目,但不知何故,在编译我的typescript时,我一直收到这些语义错误:

matchers.d.ts(4,37): error TS2503: Cannot find namespace 'jasmine'.
process/typescript/app-component.spec.ts(8,22): error TS2339: Property 'toEqual' does not exist on type 'NgMatchers'.

对于以下测试用例:

import {it, describe, expect, beforeEach, inject} from 'angular2/testing';
import {AppComponent} from "./app.component";
describe('App component test', () => {
    let component: AppComponent;
    it('Value of testvar should be test', () => {
        expect(true).toEqual(true);
    });
});

我不知道哪里出了问题,尤其是因为我正在加载茉莉花打字机。。。typeings.json

{
    "ambientDependencies": {
        "es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#7de6c3dd94feaeb21f20054b9f30d5dabc5efabd",
        "jasmine": "github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#5c182b9af717f73146399c2485f70f1e2ac0ff2b"
    }
}

gullfile.js

var gulp = require('gulp'),
    webserver = require('gulp-webserver'),
    typescript = require('gulp-typescript'),
    sourcemaps = require('gulp-sourcemaps'),
    tscConfig = require('./tsconfig.json');
gulp.task('typescript', function () {
  return gulp
    .src(tsSrc + '**/*.ts')
    .pipe(sourcemaps.init())
    .pipe(typescript(tscConfig.compilerOptions))
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest(appSrc + 'js/'));
});

tsconfig.json

{
    "compilerOptions": {
        "target": "es5",
        "module": "system",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "noImplicitAny": true
    },
    "exclude": [
        "node_modules"
    ]
}

有人知道出了什么问题吗?据我所知,我正在装载所有必要的包裹。

package.json

   "dependencies": {
        "angular2": "2.0.0-beta.15",
        "systemjs": "^0.19.24",
        "es6-promise": "^3.0.2",
        "es6-shim": "^0.35.0",
        "reflect-metadata": "0.1.2",
        "rxjs": "5.0.0-beta.2",
        "zone.js": "0.6.11"
    },
  "devDependencies": {
    "gulp": "^3.9.0",
    "gulp-sourcemaps": "^1.6.0",
    "gulp-typescript": "^2.13.0",
    "gulp-webserver": "^0.9.1",
    "http-server": "",
    "jasmine-core": "^2.4.1",
    "karma": "^0.13.22",
    "karma-chrome-launcher": "^0.2.3",
    "karma-coverage": "^0.5.5",
    "karma-jasmine": "^0.3.8",
    "remap-istanbul": "^0.6.3",
    "typescript": "^1.8.10",
    "typings": "^0.6.8"
  }

我怀疑编译器需要像这样的声明文件

/// <reference path="../node_modules/angular2/typings/browser.d.ts" />
/// <reference path="../typings/main/ambient/jasmine/index.d.ts" />
import {it, describe, expect, beforeEach, inject} from 'angular2/testing';
import {AppComponent} from "./app.component";
describe('App component test', () => {
    let component: AppComponent;
    it('Value of testvar should be test', () => {
        expect(true).toEqual(true);
    });
});