aurelia-typescript-atom
aurelia-typescript-atom copied to clipboard
HttpClient RequestBuilder type definitions missing helpers
None of the helpers that get added to RequestBuilder are documented in the aurelia-http-client.d.ts file.
@mschoneman thanks for the feedback. does aurelia-http-client.d.ts have what you are looking for?
Nope. That's the issue. The way the helpers are added is tricky (it uses the static addHelper method to add a bunch of function to the RequestBuilder class that don't show up in the definition). If you try to do the following
var http:HttpClient = // from somehwere
http.createRequest(endpoint).asPost().withContent(request).withResponseType('blob').send() ;
You get a compiler error about asPost not being defined. Here's how I updated my copy of the aurelia-http-client.d.ts definition for RequestBuilder:
declare module 'aurelia-http-client/request-builder' {
/**
* A builder class allowing fluent composition of HTTP requests.
*
* @class RequestBuilder
* @constructor
*/
export class RequestBuilder {
client: any;
transformers: any;
useJsonp: any;
constructor(client: any);
/**
* Adds a user-defined request transformer to the RequestBuilder.
*
* @method addHelper
* @param {String} name The name of the helper to add.
* @param {Function} fn The helper function.
* @chainable
*/
static addHelper(name: any, fn: any): void;
/**
* Sends the request.
*
* @method send
* @return {Promise} A cancellable promise object.
*/
send(): any;
asDelete():RequestBuilder;
asGet():RequestBuilder;
asHead():RequestBuilder;
asOptions():RequestBuilder;
asPatch():RequestBuilder;
asPost():RequestBuilder;
asPut():RequestBuilder;
asJsonp():RequestBuilder;
withUrl(url:any):RequestBuilder;
withContent(content:any):RequestBuilder;
withBaseUrl(baseUrl:any):RequestBuilder;
withParams(params:any):RequestBuilder;
withResponseType(responseType:any):RequestBuilder;
withTimeout(timeout:any):RequestBuilder;
withHeader(key:any,value:any):RequestBuilder;
withCredentials(value:any):RequestBuilder;
withReviver(reviver:any):RequestBuilder;
withReplacer(replacer:any):RequestBuilder;
withProgressCallback(progressCallback:any):RequestBuilder;
withCallbackParameterName(callbackParameterName:any):RequestBuilder;
}
}
Seems to work for me.
roger that. i will try to update the code in the ts port to include those methods so we can stick with auto generating the dts files (the compiler seems to be a bit better than i am ;))
what happened with this? I'm running into the same issue : /