Skip to content

Conversation

delvedor
Copy link
Member

@delvedor delvedor commented Apr 9, 2019

With this change, it's now easier to use TypeScript with the client.
The ApiResponse now accepts a generics that defaults to any, same for every API method that might need a body.

The documentation has been updated accordingly.

I would like to thank @fox1t for the suggestions :)

@fox1t
Copy link

fox1t commented Apr 10, 2019

LGTM

@delvedor delvedor merged commit a21281f into master Apr 10, 2019
@delvedor delvedor deleted the improve-typings branch April 10, 2019 09:40
delvedor added a commit that referenced this pull request Apr 10, 2019
The ApiResponse now accepts a generics that defaults to any, same for every API method that might need a body.
delvedor added a commit that referenced this pull request Apr 10, 2019
The ApiResponse now accepts a generics that defaults to any, same for every API method that might need a body.
delvedor added a commit that referenced this pull request Apr 10, 2019
The ApiResponse now accepts a generics that defaults to any, same for every API method that might need a body.
details: Explanation[];
}
interface SearchResponse<T> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering, why can't this part be exported by this client library directly? This seems generic enough.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there is not an official spec from which I can generate the response types, and it will make no sense export the types just for the search response.

}
}

// Define the intefrace of the source object
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"interface", not "intefrace" ;)

@onehorsetown
Copy link
Contributor

onehorsetown commented Apr 15, 2019

Shouldn't ApiMethod be typed like this, so if you are using promises and you are okay with body: any, you don't have to cast anything:

declare type callbackFn<T> = (
  err: Error | null,
  result: ApiResponse<T>
) => void;

interface ApiMethod<T, R = any> {
  (params: T, options?: TransportRequestOptions): Promise<ApiResponse<R>>;
  (params: T, callback: callbackFn<R>): void;
  (params: T, options: TransportRequestOptions, callback: callbackFn<R>): void;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants