How to use jQuery's $.post() method with async/await and typescript

前端 未结 2 1209
无人共我
无人共我 2020-12-15 21:51

My await statements inside the async functions are calls to jQuery\'s $.post() method which return a valid promise, however I am getting this error in TypeScript:

2条回答
  •  独厮守ぢ
    2020-12-15 22:26

    JQueryXHR has its own version of .then() which has some additional options:

    then(doneCallback: (data: any, textStatus: string, jqXHR: JQueryXHR) => R, failCallback?: (jqXHR: JQueryXHR, textStatus: string, errorThrown: any) => void): JQueryPromise;
    

    To use await in TypeScript with $.post, I had to remove that line from jquery.d.ts. TypeScript will then see the .then defined on JQueryGenericPromise.

提交回复
热议问题