Skip to content

fix(TS): add queries typings #259

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

Merged

Conversation

chochihim
Copy link
Contributor

What: Add typings for queries in RenderOptions

Why: It's missing. Also in a project I need to add some custom queries.

How:

Checklist:

  • Documentation
  • Tests
  • Ready to be merged
  • Added myself to contributors table

The implementation is trickier than I thought. Any comment is appreciated. Also Query and Queries should probably be declared in dom-testing-library. I can create another PR once the implementation of this PR is accepted.

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not good enough at typescript yet to know whether this is 👍 but I'll go ahead and merge it and hope that it is 😬

@kentcdodds kentcdodds merged commit 730ee2a into testing-library:master Jan 4, 2019
@kentcdodds
Copy link
Member

Thanks!

@kentcdodds
Copy link
Member

🎉 This PR is included in version 5.4.3 🎉

The release is available on:

Your semantic-release bot 📦🚀


export * from 'dom-testing-library'

type GetsAndQueries = ReturnType<typeof getQueriesForElement>
interface Query extends Function {
(container: HTMLElement, ...args): HTMLElement[] | HTMLElement | null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chochihim @kentcdodds heads up, the ...args expression here causes TS builds to fail when --noImplicitAny is set.

Type error: Rest parameter 'args' implicitly has an 'any[]' type.  TS7019

    4 |
    5 | interface Query extends Function {
  > 6 |   (container: HTMLElement, ...args): HTMLElement[] | HTMLElement | null
      |                            ^
    7 | }
    8 |
    9 | interface Queries {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😬

Could you please open a PR to fix this @joeporpeglia.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha! #260

lucbpz pushed a commit to lucbpz/react-testing-library that referenced this pull request Jul 26, 2020
* docs: update README.md

* docs: update .all-contributorsrc

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
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 this pull request may close these issues.

3 participants