Currently, I am utilizing TypeScript 2.3.2 within Visual Studio Code and it is a new experience for me. My main goal is to develop a front-end client for a SharePoint backend system. To achieve this, I have integrated the SPServices plugin from SharePoint that enables me to retrieve a JSON object through a call, with the method returning a $.Deffered() object. The logic behind SPServices involves calling resolveWith() and passing the results of the SharePoint query in a specific format:
var thisResult = {
changeToken: newChangeToken,
mapping: thisListJsonMapping,
data: jsonData,
deletedIds: deletedIds
};
result.resolveWith(thisResult);
Below is a snippet of my code showcasing how I handle the resolution process:
$.when(promise)
.then(res => {
let me = this;
debugger;
});
After numerous attempts at refining the code, I found that "res" remained unassigned and the context of "this" in TypeScript indicated the class when I inspected it in Chrome's debugging tool. Upon checking the console and viewing "this", I noticed the object passed during the resolveWith() operation earlier.
All the tutorials I studied emphasized that "res" should be assigned the JSON object present in "thisResults". However, there seems to be a misalignment somewhere. Any insights into why this discrepancy exists?
UPDATE: Upon implementing the suggestions provided below, I conducted additional testing following the development of a backup plan. Interestingly, after modifying the SPServices library to use result.resolve(thisResult);
instead of resolveWith(thisResult);
, the object was successfully returned to the lambda function.