ajax - Typing a jQuery extension -


someone else wrote extension. surfaces ajax progress events syntax this:

$.ajax(url)   .progress(function(e) {     // tracking downloading   })   .uploadprogress(function(e) {     // tracking uploading     // if (e.lengthcomputable) {     //  var percentage = math.round((e.loaded * 100) / e.total);     //  console.log(percentage);     //}   }); 

typescript complains these new methods don't exist.

it seems me need somehow add them jqueryxhr defined in jquery.d.ts definitelytyped. being third party library don't want edit - interfere updates.

how go adding method typescript interface has been defined in file don't want edit?

how go adding method typescript interface has been defined in file don't want edit

typescript interfaces open ended , designed accomodate this.

just create thelib.d.ts with:

interface jqueryxhr {   progress: any;   uploadprogress: any; } 

more

https://basarat.gitbooks.io/typescript/content/docs/types/ambient/interfaces.html


same stronger typing

the answer given addresses question asked, , has advantage of simplicity. in field need better. here stronger typing. matters if want "fluent" eg .then().fail().done() etc.

interface jqueryxhr {   progress<r>(callback: (e: progressevent, status: string) => r): jquerypromise<r>;   uploadprogress<r>(callback: (e: progressevent, status: string) => r): jquerypromise<r>; } 

you don't need triple-slash reference. presumably it's because jquerypromise in scope main definition of jqueryxhr.


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -