【问题标题】:web api with angular errors带有角度错误的 web api
【发布时间】:2019-01-29 03:14:51
【问题描述】:

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 活跃

【问题讨论】:

  • 如果您展示了引发错误的代码会有所帮助。
  • @Ron Beyer 我无法上传图片可以发给你吗?
  • 代码是文本,请edit your question并在其中添加代码。代码图片并没有太大帮助,因为我们无法复制/粘贴,并且某些图像不会显示在某些人的计算机上。
  • @Ron Beyer 已完成
  • 嘿@itaytal。你能告诉我们你正在使用哪个版本的 TypeScript 和 RxJS(检查你的 package.json 文件)吗?看起来其他人过去可能经历过这种情况。 github.com/angular/angular/issues/17800

标签: c# angular asp.net-web-api web


【解决方案1】:

对于错误 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);
  });

});

【讨论】:

    猜你喜欢
    • 2019-10-06
    • 2015-04-07
    • 2021-04-27
    • 2013-04-26
    • 1970-01-01
    • 2016-04-21
    • 1970-01-01
    • 1970-01-01
    • 2019-11-22
    相关资源
    最近更新 更多