首页 > 解决方案 > 带有角度错误的 web api

问题描述

import { browser, element, by } from 'protractor';

describe('QuickStart E2E Tests', function () {

  let expectedMsg = 'Hello Angular';

  beforeEach(function () {
    browser.get('');
  });

  it('should display: ' + expectedMsg, function () {
    expect(element(by.css('h1')).getText()).toEqual(expectedMsg);
  });

});

import { Operator } from './Operator';
import { Observer } from './Observer';
import { Observable } from './Observable';
import { Subscriber } from './Subscriber';
import { ISubscription, Subscription } from './Subscription';
/**
 * @class SubjectSubscriber<T>
 */
export declare class SubjectSubscriber<T> extends Subscriber<T> {
    protected destination: Subject<T>;
    constructor(destination: Subject<T>);
}
/**
 * @class Subject<T>
 */
export declare class Subject<T> extends Observable<T> implements ISubscription {
    observers: Observer<T>[];
    closed: boolean;
    isStopped: boolean;
    hasError: boolean;
    thrownError: any;
    constructor();
    static create: Function;
    lift<R>(operator: Operator<T, R>): Observable<T>;
    next(value?: T): void;
    error(err: any): void;
    complete(): void;
    unsubscribe(): void;
    protected _subscribe(subscriber: Subscriber<T>): Subscription;
    asObservable(): Observable<T>;
}
/**
 * @class AnonymousSubject<T>
 */
export declare class AnonymousSubject<T> extends Subject<T> {
    protected destination: Observer<T>;
    constructor(destination?: Observer<T>, source?: Observable<T>);
    next(value: T): void;
    error(err: any): void;
    complete(): void;
    protected _subscribe(subscriber: Subscriber<T>): Subscription;
}

我刚刚使用 Angular 打开了一个新的 web api 项目。这是我第一次使用 Angular。我按照本指南工作:https ://angular.io/guide/visual-studio-2015 但我遇到了错误。有谁知道如何解决这个问题?谢谢!

错误1:

严重性代码 描述 项目文件行抑制状态错误 TS2416 (TS) 类型“主题”中的属性“提升”不能分配给基本类型“可观察”中的相同属性。类型 '(operator: Operator) => Observable' 不可分配给类型 '(operator: Operator) => Observable'。类型“Observable”不可分配给类型“Observable”。类型“T”不能分配给类型“R”。C:\Users\איתי\source\repos\Ctaxi - WeWorkShop\Ctaxi - WeWorkShop\src(tsconfig 或 jsconfig 项目) C:\Users\איתי\source\repos\Ctaxi - WeWorkShop\Ctaxi - WeWorkShop\node_modules\rxjs\Subject .d.ts 24 活动

错误2:

严重性代码 描述 项目文件行抑制状态错误 TS2559 (TS) 类型“By”与类型“Locator”没有共同的属性。C:\Users\איתי\source\repos\Ctaxi - WeWorkShop\Ctaxi - WeWorkShop\e2e(tsconfig 或 jsconfig 项目) C:\Users\איתי\source\repos\Ctaxi - WeWorkShop\Ctaxi - WeWorkShop\e2e\app.e2e -spec.ts 12 活动

标签: c#angularasp.net-web-apiweb

解决方案


对于错误 2:需要对“by.css('h1'))”进行强制转换并导入定位器

import { browser, element, by } from 'protractor';
import { By } from 'selenium-webdriver';
import { Locator } from 'protractor/built/locators';

describe('QuickStart E2E Tests', function () {

  let expectedMsg = 'Hello Angular';

  beforeEach(function () {
    browser.get('');
  });

  it('should display: ' + expectedMsg, function () {
    expect(element(<Locator>by.css('h1')).getText()).toEqual(expectedMsg);
  });

});


推荐阅读