I am getting this error and I am not sure why. In my dialog class I have the Promse and the fail logic. I am getting this build error any help would be great.
Severity Code Description File Project Line Suppression State Error TS2740 (TS) Type 'Promise' is missing the following properties from type 'JQueryPromise': state, always, done, fail, and 2 more.
var responsePromse = this.agentManager.getStyleGuideByAgentId(this.model.Id);
responsePromse.then((response) => {
this.styleguideNote.AgentType = response.responseObject.Name;
}).fail(() => {
this.relatedTemplates.loadingState = 0;
});
AgentManager
getStyleGuideByAgentId(Id: number): JQueryPromise<any> {
var request = this.agentsService.getStyleGuideByAgentId(Id);
console.log(request);
return request;
}
AgentService
getStyleGuideByAgentId(Id: number) {
var x = this.http.post(this.apiUrls.GetStyleGuideNotes, JSON.stringify(Id), { headers: ServiceBase.headers }).toPromise();
return x;
}
Conroller
[HttpPost]
public IHttpActionResult GetStyleGuideNoteById(long agentId)
{
var dbResult = StyleGuideNotesDataService.GetStyleGuideNoteById(agentId);
var styleguideNote = dbResult
.Select(x=> new
{
Section =x.Section,
AgentType = x.AgentType,
Status = x.Status.Name
})
.Distinct()
.ToList();
return Ok(styleguideNote);
}
CodePudding user response:
TS Error message like this format Type 'A' is missing following properties from type 'B'
means that, you typed 'B' explicitly to a value, but type of the value is actually 'A'.
so, You typed something explicitly as JQueryPromise
, but that thing was actually Promise
.
I think this code makes error.
getStyleGuideByAgentId(Id: number): JQueryPromise<any> {
var request = this.agentsService.getStyleGuideByAgentId(Id);
console.log(request);
return request;
}
I'm not sure but getStyleGuideByAgentId
actually returns standard Promise, not JqueryPromise due to toPromise()
so, changing code like this might be solve your problem.
async getStyleGuideByAgentId(Id: number): Promise<any> {
var request = await this.agentsService.getStyleGuideByAgentId(Id);
console.log(request);
return request;
}