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

[algoliasearch] Search Response made generic #33111

Merged
merged 1 commit into from
Feb 20, 2019

Conversation

neryortez
Copy link
Contributor

This is to allow better linting on the hits of the Reponse object

Please fill in this template.

  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Test the change in your own code. (Compile and run.)
  • Add or edit tests to reflect the change. (Run with npm test.)
  • [x ] Follow the advice from the readme.
  • [x ] Avoid common mistakes.
  • [x ] Run npm run lint package-name (or tsc if no tslint.json is present).

If changing an existing definition:

  • Provide a URL to documentation or source code which provides context for the suggested changes: <>
  • Increase the version number in the header if appropriate.
  • If you are making substantial changes, consider adding a tslint.json containing { "extends": "dtslint/dt.json" }.

Response made generic to allow better linting on the items of the `Reponse`
@typescript-bot
Copy link
Contributor

typescript-bot commented Feb 16, 2019

@neryortez Thank you for submitting this PR!

🔔 @CBaptiste @Haroenv @aherve @samouss @keichinger - please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead.

@@ -1842,8 +1843,8 @@ declare namespace algoliasearch {
cursor?: string;
}

interface MultiResponse {
results: Response[];
interface MultiResponse<T=any> {
Copy link
Contributor

Choose a reason for hiding this comment

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

The signature of the function is not helpful when we target different indices. The type of the record is different in most cases. With this signature the response only contain records of the same type.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is a particular problem since you could simply define a union type as T, like in this example:

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@keichinger is right. Either way, if you just have too many types, you can also leave blank like before:

client.search(...)

The T type is optional.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, but you have to use a type guard to safely access your hit from the response. What I meant with my comment is: with this signature the response is not tightly coupled to a specific type which is the case with the single query signature.

Copy link
Contributor

Choose a reason for hiding this comment

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

@samouss All good?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes it’s better than nothing.

@typescript-bot typescript-bot added Owner Approved A listed owner of this package signed off on the pull request. Merge:Express and removed Awaiting reviewer feedback labels Feb 18, 2019
@typescript-bot
Copy link
Contributor

A definition owner has approved this PR ⭐️. A maintainer will merge this PR shortly. If it shouldn't be merged yet, please leave a comment saying so and we'll wait. Thank you for your contribution to DefinitelyTyped!

@gabritto gabritto merged commit 850fdf0 into DefinitelyTyped:master Feb 20, 2019
@typescript-bot
Copy link
Contributor

I just published @types/algoliasearch@3.30.5 to npm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Owner Approved A listed owner of this package signed off on the pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants