【发布时间】:2017-11-27 11:12:40
【问题描述】:
我刚刚对我们的 Angular 4 应用程序和构建工具进行了两次重要升级:
-
@angular/core
^4.1.3=>^4.2.4(和 /http、/forms 等) -
tslint
^5.3.2=>^5.4.3
我有一个服务,它声明如下选项:
@Injectable()
export class WorkOrderService {
private headers: Headers = new Headers({ 'Content-Type': 'application/json' });
private options: RequestOptions = new RequestOptions(this.headers);
constructor(private http: Http) {}
/* Methods ... */
}
上面现在不再验证 tslint,抛出以下错误:
错误 TS2559:“Headers”类型与“RequestOptionsArgs”类型没有共同的属性。
来源 (@angular/http interface.d.ts:43) 明确允许将 Headers 用作 RequestOptionsArgs:
/**
* Interface for options to construct a RequestOptions, based on
* [RequestInit](https://fetch.spec.whatwg.org/#requestinit) from the Fetch spec.
*
* @experimental
*/
export interface RequestOptionsArgs {
url?: string | null;
method?: string | RequestMethod | null;
/** @deprecated from 4.0.0. Use params instead. */
search?: string | URLSearchParams | {
[key: string]: any | any[];
} | null;
params?: string | URLSearchParams | {
[key: string]: any | any[];
} | null;
headers?: Headers | null;
body?: any;
withCredentials?: boolean | null;
responseType?: ResponseContentType | null;
}
【问题讨论】:
标签: angular typescript