Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No typings on search body, other than Record<string, any> #942

Closed
paul-uz opened this issue Dec 16, 2024 · 16 comments · Fixed by #944
Closed

No typings on search body, other than Record<string, any> #942

paul-uz opened this issue Dec 16, 2024 · 16 comments · Fixed by #944

Comments

@paul-uz
Copy link

paul-uz commented Dec 16, 2024

Is there a way to get better typings on the body of a search result for example?

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

I see there is SearchResponse for Msearch, but not Search

@nhtruong
Copy link
Collaborator

@paul-uz which version of the client are you using? We're testing Version 3.0.0 with beta-8 already out that have all request and response types.

@paul-uz
Copy link
Author

paul-uz commented Dec 16, 2024

Just using the latest stable release, set as ^2.13.0 in our package file. When will V3 be released officially?

@nhtruong
Copy link
Collaborator

The current beta version is going to be very close to the final version. We're trying to get more people to test the beta before releasing it. We're aiming to release by year end.

@paul-uz
Copy link
Author

paul-uz commented Dec 16, 2024

I just installed beta-8, and whilst i can click through and find the new type ie

export type Search_Response = ApiResponse & {
  body: Search_ResponseBody;
}

body is just showing as any in my IDE, VSCode :/

@paul-uz
Copy link
Author

paul-uz commented Dec 16, 2024

VSCode intellisense gives me this typing

const response: {
    body: any;
    statusCode: number | null;
    headers: Record<string, any> | null;
    warnings: string[] | null;
    meta: {
        context: unknown;
        name: string | symbol;
        request: {
            params: TransportRequestParams;
            options: TransportRequestOptions;
            id: any;
        };
        connection: Connection;
        attempts: number;
        aborted: boolean;
        sniff?: {
            hosts: any[];
            reason: string;
        } | undefined;
    };
    body: ResponseBody;
}

body is deifned twice somehow

@nhtruong
Copy link
Collaborator

The typing in this comment is coming from the 2.x version. Make sure that the 2.x package has been removed from your env.

@paul-uz
Copy link
Author

paul-uz commented Dec 17, 2024

The typing in this comment is coming from the 2.x version. Make sure that the 2.x package has been removed from your env.

I simply installed the beta over the top via NPM.

I'll try removing node_modules and reinstalling.

@paul-uz
Copy link
Author

paul-uz commented Dec 18, 2024

@nhtruong did a full removal of node_modules and package-lock, installed the latest beta, typings still broken, still two instances of body in the types

@paul-uz
Copy link
Author

paul-uz commented Dec 18, 2024

Code from 3.0.0-beta.8

export type Search_Response = ApiResponse & {
  body: Search_ResponseBody;
}
export interface ApiResponse {
  body: any;
  statusCode: number | null;
  headers: Record<string, any> | null;
  warnings: string[] | null;
  meta: {
    context: unknown;
    name: string | symbol;
    request: {
      params: TransportRequestParams;
      options: TransportRequestOptions;
      id: any;
    };
    connection: Connection;
    attempts: number;
    aborted: boolean;
    sniff?: {
      hosts: any[];
      reason: string;
    };
  };
}

@paul-uz
Copy link
Author

paul-uz commented Dec 18, 2024

Beta 7

export interface Search_Response extends ApiResponse {
  body: Search_ResponseBody;
}

there's the bug ;)

@nhtruong
Copy link
Collaborator

That's super odd. I'll look into it. Thanks for the finding.

@paul-uz
Copy link
Author

paul-uz commented Dec 18, 2024

That's super odd. I'll look into it. Thanks for the finding.

Yea looks like the change to a type union broke it. Happy to PR to revert if there is a workflow for contributions to V3?

@paul-uz
Copy link
Author

paul-uz commented Dec 18, 2024

PR open, please let me know if I;'ve done it correctly.

@nhtruong
Copy link
Collaborator

Thanks @paul-uz The fix is gonna be a bit more involved than that because that file was generated from the spec. I'm going to update the generator.

@paul-uz
Copy link
Author

paul-uz commented Dec 18, 2024

I'll leave it in your capable hands haha.

@nhtruong
Copy link
Collaborator

nhtruong commented Dec 19, 2024

@paul-uz beta-9 is out with the fix.
If you find any more issues with it, please dont hesitate to let us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants