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

[bug]: TS recursivity error in SearchResponse #1571

Open
ChrisRast opened this issue Nov 29, 2024 · 0 comments
Open

[bug]: TS recursivity error in SearchResponse #1571

ChrisRast opened this issue Nov 29, 2024 · 0 comments
Labels

Comments

@ChrisRast
Copy link

ChrisRast commented Nov 29, 2024

Description

We encountered the issue Type instantiation is excessively deep and possibly infinite.ts(2589) while upgrading algoliasearch from v5.1 to v5.15 and working with Immer produce function and SearchResponse type.

Here's a reproducible example of the issue:

The issue stems from two types: highlightResult and snippetResult(which both have the same structure). They create a recursive reference in the Yaml definition here where highlightResultMap and highlightResultArray both reference the same highlightResult.

highlightResultArray:
  type: array
  description: Surround words that match the query with HTML tags for highlighting.
  items:
    $ref: '#/highlightResult'

highlightResultMap:
  type: object
  description: Surround words that match the query with HTML tags for highlighting.
  additionalProperties:
    x-additionalPropertiesName: attribute
    $ref: '#/highlightResult'

highlightResult:
  oneOf:
    - $ref: '#/highlightResultOption'
    - $ref: '#/highlightResultMap'
    - $ref: '#/highlightResultArray'

This type actually changed in the previous commits and did not create any issue in v5.1.0. Last working version is 5.3.2.

We see two possible fixes:

  1. Create a new highlightResultLevelTwo that won't reference highlightResultMap or highlightResultArray and breaks the cycle.
  2. Patch the TS definitions to prevent a excessively deep recursion. TS Playground with a modified type HighlightResult as generic

Thanks!

Client

Search

Version

5.15.0

Relevant log output

No response

@ChrisRast ChrisRast added the bug label Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant