Skip to content

ajax() type signature error (TS) when string provided #1382

@staltz

Description

@staltz

John Lindquist reported that

import {Observable} from 'rxjs/Rx.DOM';
Observable.ajax('http://swapi.co/api/people/1/')
    .subscribe();

gives TS compile error

ERROR in ./src/main.ts
(2,1): error TS2346: Supplied parameters do not match any signature of call target.

Solution suggestion:
I think the type signature should be changed like this:

 export interface AjaxCreationMethod {
-  (): <T>(urlOrRequest: string | AjaxRequest) => Observable<T>;
+  <T>(urlOrRequest: string | AjaxRequest): Observable<T>;
   get: <T>(url: string, resultSelector?: (response: AjaxResponse) => T, headers?: Object) => Observable<T>;
   post: <T>(url: string, body?: any, headers?: Object) => Observable<T>;
   put: <T>(url: string, body?: any, headers?: Object) => Observable<T>;
   delete: <T>(url: string, headers?: Object) => Observable<T>;
   getJSON: <T, R>(url: string, resultSelector?: (data: T) => R, headers?: Object) => Observable<R>;
 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    TSIssues and PRs related purely to TypeScript issueshelp wantedIssues we wouldn't mind assistance with.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions