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 type #1421

Closed
bidoubiwa opened this issue Dec 12, 2022 · 0 comments · Fixed by #1424
Closed

Remove Document and Documents type #1421

bidoubiwa opened this issue Dec 12, 2022 · 0 comments · Fixed by #1424
Labels
enhancement New feature or request

Comments

@bidoubiwa
Copy link
Contributor

With the same logic as in this PR #1416

the Document and Documents type should be removed:

export type Document<T = Record<string, any>> = T
export type Documents<T = Record<string, any>> = Array<Document<T>>

and instead, the declaration in indexes.getDocument and indexes.getDocuments should inherit the generic T from the class declaration if no other type has been specified.

Example with getDocument

async getDocument<T = Record<string, any>>(
documentId: string | number,
parameters?: DocumentQuery<T>
): Promise<Document<T>> {
const url = `indexes/${this.uid}/documents/${documentId}`
const fields = (() => {
if (Array.isArray(parameters?.fields)) {
return parameters?.fields?.join(',')
}
return undefined
})()
return await this.httpRequest.get<Document<T>>(
url,
removeUndefinedFromObject({
...parameters,
fields,
})
)
}

Should be changed:

async getDocument<D = T>(
    documentId: string | number,
    parameters?: DocumentQuery<T>
  ): Promise<D> {

and the response object

 return await this.httpRequest.get<D>(
      url,
      removeUndefinedFromObject({
        ...parameters,
        fields,
      })
    )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant