opensearch-project / opensearch-js

Node.js Client for OpenSearch
https://opensearch.org/docs/latest/clients/javascript/
Apache License 2.0
188 stars 121 forks source link

[PROPOSAL] Fix the type definitions #523

Open sam-goodwin opened 1 year ago

sam-goodwin commented 1 year ago

The type definitions in this library seem to not include the response type.

E.g. here is the index type definitions.

index<
    TResponse = Record<string, any>,
    TRequestBody extends RequestBody = Record<string, any>,
    TContext = Context
  >(
    params?: RequestParams.Index<TRequestBody>,
    options?: TransportRequestOptions
  ): TransportRequestPromise<ApiResponse<TResponse, TContext>>;

Why do I need to specify TResponse. I understand having to specify the TRequestBody to specify the type of the data i'm sending, but why doesn't the library automatically know that TResponse should be IndexResponse?

wbeckler commented 1 year ago

This makes sense and I see no logic to the current arrangement. Feel free to submit a PR if you want.