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

remove Document and Documents #1424

Merged
merged 2 commits into from
Dec 13, 2022
Merged

remove Document and Documents #1424

merged 2 commits into from
Dec 13, 2022

Conversation

trim21
Copy link
Contributor

@trim21 trim21 commented Dec 13, 2022

Pull Request

Related issue

Fixes #1421

What does this PR do?

remove Document and Documents

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!

@@ -327,10 +327,10 @@ class Index<T extends Record<string, any> = Record<string, any>> {
* @param parameters - Parameters applied on a document
* @returns Promise containing Document response
*/
async getDocument<T = Record<string, any>>(
async getDocument<D extends Record<string, any> = T>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to keep extending here? Maybe there is a case that I don't see. Is D = T not enough ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

T extends Record<string, any> on index creation but you can override it by Index<{}>().getDocument<number>()

Copy link
Contributor

@bidoubiwa bidoubiwa Dec 13, 2022

Choose a reason for hiding this comment

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

I see, but imagine I want to get Movie documents

type Movie = {
   id: number
   name: string
}

Then, overwrite the type of index by doing like you said client.index('x').getDocument<Movie>(1).

In this case Movie is doing to be D. But why does D needs to be extended from Record<string, any> ? I'm not expecting any other field in my Movie.

Sorry if I'm misunderstanding something

Copy link
Contributor Author

Choose a reason for hiding this comment

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

your type Movie already extends Record<string, any>

it's valid to call getDocument<Movie>() with your type example

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I see! Thanks :)

Copy link
Contributor

Choose a reason for hiding this comment

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

In the same vain, should we have added that as well in search ?

async searchGet<D = T>(

 async searchGet<D extends Record<string, any>> = T>( 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

@bidoubiwa bidoubiwa left a comment

Choose a reason for hiding this comment

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

LGTM 🔥

@bidoubiwa bidoubiwa added skip-changelog The PR will not appear in the release changelogs maintenance Issue about maintenance (CI, tests, refacto...) labels Dec 13, 2022
@bidoubiwa
Copy link
Contributor

bors merge

@meili-bors
Copy link
Contributor

meili-bors bot commented Dec 13, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Issue about maintenance (CI, tests, refacto...) skip-changelog The PR will not appear in the release changelogs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove Document and Documents type
2 participants