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

HighlightHitParams attribute type should allow number for array indexing #1261

Closed
aldenquimby opened this issue Jul 8, 2024 · 1 comment · Fixed by #1262
Closed

HighlightHitParams attribute type should allow number for array indexing #1261

aldenquimby opened this issue Jul 8, 2024 · 1 comment · Fixed by #1262

Comments

@aldenquimby
Copy link
Contributor

Description

  • Algolia currently allows highlighting array fields like this:
      {hit._highlightResult.tagNames.map((_, i) => (
        <Fragment key={i}>
          {i !== 0 ? ', ' : null}
          {components.Highlight({
            hit,
            // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- array index is allowed, type is off
            // @ts-expect-error
            attribute: ['tagNames', i],
          })}
        </Fragment>
      ))}
  • example showing this works:
    image

  • ideally the above code would not require the ts-ignore / eslint-ignore

Reproduction

  • I am not sure how to create a preview for this, because it depends on the server-side index having an array field

Preview →

Steps

  • see code above

Expected behavior

  • no type/lint suppression is required

Environment

  • OS: [e.g. Windows / Linux / macOS / iOS / Android]: all
  • Browser: [e.g. Chrome, Safari]: all
  • Autocomplete version: [e.g. 1.0.0]: 1.17.2
@Haroenv
Copy link
Contributor

Haroenv commented Jul 8, 2024

Thanks for creating a PR. Alternatively you could also cast the index as a string (that's what the interpreter would do anyway), but I think it makes sense to change

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

Successfully merging a pull request may close this issue.

2 participants