Skip to content

Make screen query methods generic #1033

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

Closed
nstepien opened this issue Sep 15, 2021 · 3 comments · Fixed by #1034
Closed

Make screen query methods generic #1033

nstepien opened this issue Sep 15, 2021 · 3 comments · Fixed by #1034
Labels

Comments

@nstepien
Copy link
Contributor

  • @testing-library/dom version: 8.5.0
  • Testing Framework and version: [email protected]
  • DOM Environment: jsdom

Relevant code or config:

import { screen } from '@testing-library/dom';

screen.getByText<HTMLElement>('test');

What you did:

Defined a type argument for getByText

What happened:

> tsc

test.ts:3:18 - error TS2558: Expected 0 type arguments, but got 1.

3 screen.getByText<HTMLElement>('test');
                   ~~~~~~~~~~~

Reproduction:

import { screen } from '@testing-library/dom';

screen.getByText<HTMLElement>('test');

Problem description:

While the methods are generic, the way they're redefined on the screen object for example makes them lose their genericness.
Original request: #615
PR which made the methods generic: #1023

Suggested solution:

@eps1lon eps1lon added enhancement New feature or request TypeScript labels Sep 16, 2021
@eps1lon eps1lon changed the title Generic methods are not generic Make screen query methods generic Sep 16, 2021
@timdeschryver
Copy link
Member

I tried to solve this, but AFAIK there isn't a way to "automatically" add the generic to the queries of the screen object.
The only way I was able to add a generic, was to manually add the queries on screen.

I'll leave this open for someone that is able to add the generic "automatically".
If no-one is able to do this, I can open a PR with my current implementation.

@eps1lon
Copy link
Member

eps1lon commented Sep 18, 2021

If no-one is able to do this, I can open a PR with my current implementation.

Let's start with this. We can always improve later though from my understanding, we can't carry generics over automatically. So the manual approach is probably going to stick for a while.

@github-actions
Copy link

🎉 This issue has been resolved in version 8.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

3 participants