TypeScript 2.6.1错误TS2554:预期2-3个参数,但得到1
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TypeScript 2.6.1错误TS2554:预期2-3个参数,但得到1相关的知识,希望对你有一定的参考价值。
我在angularjs5中有这个错误,
src / app / search / job.search.ts(17,10):错误TS2554:预期2-3个参数,但得到1. src / app / search / job.search.ts(21,10):错误TS2554:预期2-3个论点,但得到1。
这是我的代码:
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import 'rxjs/add/operator/map';
@Injectable()
export class JobSearch{
constructor(private _http: Http){}
private _jobListUrl = 'https://api.shiftjobapp.com/api/v3/job_list?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjIzMjQsImlzcyI6Imh0dHA6XC9cL2FwaS5zaGlmdGpvYmFwcC5jb21cL2FwaVwvdjNcL2F1dGhlbnRpY2F0ZV9qb2Jfc2Vla2VyIiwiaWF0IjoxNTEyMzY3OTg1LCJleHAiOjE1MTMyMzE5ODUsIm5iZiI6MTUxMjM2Nzk4NSwianRpIjoiMWQ4NmZkZDYzZDI3YmFiODE0NjA5OTRjOGZhYjI4NTUifQ.3EzNsu154q7a6xFuhQSakBlC-rj1D0HZqLiuwHblNao';
private _jobDetailsUrl = 'https://api.shiftjobapp.com/api/v3/job_detailed?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjIzMjQsImlzcyI6Imh0dHA6XC9cL2FwaS5zaGlmdGpvYmFwcC5jb21cL2FwaVwvdjNcL2F1dGhlbnRpY2F0ZV9qb2Jfc2Vla2VyIiwiaWF0IjoxNTEyMzY3OTg1LCJleHAiOjE1MTMyMzE5ODUsIm5iZiI6MTUxMjM2Nzk4NSwianRpIjoiMWQ4NmZkZDYzZDI3YmFiODE0NjA5OTRjOGZhYjI4NTUifQ.3EzNsu154q7a6xFuhQSakBlC-rj1D0HZqLiuwHblNao';
getJobs(){
return this._http.post(this._jobListUrl)
.map((response:Response) => response.json());
}
getJobDetails(){
return this._http.post(this._jobDetailsUrl)
.map((response:Response) => response.json());
}
}
答案
POST
请求需要数据
例如,参见
addHero (hero: Hero): Observable<Hero> {
return this.http.post<Hero>(this.heroesUrl, hero, httpOptions).pipe(
tap((hero: Hero) => this.log(`added hero w/ id=${hero.id}`)),
catchError(this.handleError<Hero>('addHero'))
);
}
来自https://angular.io/tutorial/toh-pt6
以上是关于TypeScript 2.6.1错误TS2554:预期2-3个参数,但得到1的主要内容,如果未能解决你的问题,请参考以下文章
错误 TS2554:预期 2 个参数,但使用 @ViewChild 得到 1 个
带有 Typescript 错误 TS18003 的 Npm 服务器
Typescript 编译错误:错误 TS1109:预期表达式