Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Type Promose<Response> is missing

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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);
        }

>Solution :

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;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading