[bug]: TS recursivity error in SearchResponse

オープン
#1,571 コメント 0 件 リアクション 7 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
typescript
領域
api

調査の方向性

リンクされた TS Playground を使って TypeScript 5.6.3 のエラーを再現し、生成された SearchResponse、highlightResult、snippetResult の定義を specs/common/schemas/HighlightResult.yml と照らし合わせて調査します。highlightResultMap と highlightResultArray の再帰参照を追跡し、その後、最後に動作していた v5.3.2 の型と比較します。v5.15 の定義がレスポンスの形状を維持したまま TS2589 なしでコンパイルできれば完了です。

索引モデルが issue の本文から書いたものです。

説明

bug
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

主要言語
TypeScript
スター
1.4k
フォーク
227
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

algolia/algoliasearch-client-javascript のほかの issue

algolia/algoliasearch-client-javascript の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。