Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Setup for custom queries clashes with AllByAttribute type

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

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

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
48/100
issue の種類
ドキュメント
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
typescript
領域
documentation

調査の方向性

issue にリンクされているカスタムクエリの設定ページから始め、その JavaScript の例を報告された TypeScript 変換と比較します。カスタムクエリがドキュメントに記載された型と buildQueries の使用方法に準拠するように例を更新し、TypeScript 版で報告された型エラーが発生しなくなったことを確認します。

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

説明

Describe the bug
https://testing-library.com/docs/react-testing-library/setup#add-custom-queries

Existing setup for custom queries documentation does not work with typescript

To Reproduce
converting the following to typescript

const queryAllByDataCy = (...args) =>
  queryHelpers.queryAllByAttribute('data-cy', ...args)
const queryAllByDataCy: AllByAttribute = (_, ...args) =>
  queryHelpers.queryAllByAttribute('data-cy', ...args)

Produces a type error in the buildQueries function
type error

Argument of type 'AllByAttribute' is not assignable to parameter of type 'GetAllBy<[container: HTMLElement, id: Matcher, options?: MatcherOptions | undefined]>'.                                                                   
  Types of parameters 'attribute' and 'container' are incompatible.                                                                                                                                                                                                               
    Type 'HTMLElement' is not assignable to type 'string'.                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                  
buildQueries(queryAllByDataCy, getMultipleError, getMissingError) 

Expected behavior
When converting the provided example to typescript the setup example should be in a format that conforms to the libraries type AllByAttribute.

This can be done by using partial application the container argument on queryHelpers.queryAllByAttribute and then updating the type of AllByAttribute to omit the partial argument
e.g.

js only:

const queryAllByDataCy = queryHelpers.queryAllByAttribute,bind(null, 'data-cy')

ts only:

type QueryAllByDataCy = (
  container: HTMLElement,
  id: Matcher,
  options?: MatcherOptions
 ) => HTMLElement[]

const queryAllByDataCy: QueryAllByDataCy = queryHelpers.queryAllByAttribute,bind(null, 'data-cy')

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Ubuntu 20.04.2 LTS
  • Typescript ^4.2.4
  • Node 15.14.0
主要言語
JavaScript
スター
479
フォーク
738
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

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

testing-library/testing-library-docs のほかの issue

testing-library/testing-library-docs の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

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

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