You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This would require to add a type check in each function to see if the callbacks have been provided. If not, the function could return a Promise.
Here's a sample implementation for the query function:
typeQueryOverload={/** * Executes the specified SOQL query. * @param soql a string containing the query to execute - e.g. "SELECT Id, * Name from Account ORDER BY Name LIMIT 20" * @param callback function to which response will be passed * @param [error=null] function called in case of error * @returns void */<T>(soql: string,successCB: ExecSuccessCallback<T>,errorCB: ExecErrorCallback): void;/** * Executes the specified SOQL query. * @param soql a string containing the query to execute - e.g. "SELECT Id, * Name from Account ORDER BY Name LIMIT 20" * @returns Promise<T> */<T>(soql: string): Promise<T>;};exportconstquery: QueryOverload=<T>(soql: string,successCB?: ExecSuccessCallback<T>,errorCB?: ExecErrorCallback): any=>{if(successCB&&errorCB){sendRequest("/services/data",`/${apiVersion}/query`,successCB,errorCB,"GET",{q: soql});}else{returnnewPromise((resolve,reject)=>{constsuccessCallback=(results: T)=>resolve(results);consterrorCallback: ExecErrorCallback=(error)=>reject(error);sendRequest("/services/data",`/${apiVersion}/query`,successCallback,errorCallback,"GET",{q: soql});});}};query("SELECT Id FROM Account").then((results)=>console.log(results)).catch((err)=>console.error(err));query("SELECT Id FROM Account",(results)=>console.log(results),(err)=>console.error(err),);
And of course, we would benefit from the IntelliSense for both versions of the function.
The text was updated successfully, but these errors were encountered:
@wmathurin As mentioned above, here are the limitations with promiser:
This does not work for all methods (sendRequest is a good example of a method that breaks with promiser, because the order of parameters is inconsistent)
It completely strips the types off when used in TypeScript, as promiser cannot predict the future type of the function created.
It would be great to support promises without having to rely on the promiser, in order to:
sendRequest
, wheresuccessCB
anderrorCB
are not the last arguments)syncName
insyncUp
).This would require to add a type check in each function to see if the callbacks have been provided. If not, the function could return a Promise.
Here's a sample implementation for the
query
function:And of course, we would benefit from the IntelliSense for both versions of the function.
The text was updated successfully, but these errors were encountered: