Closed
Description
Describe the feature you'd like:
I know the element type I'm querying, so it'd be beneficial to specify it upfront:
screen.queryByText<HTMLButtonElement>('click me'); // -> HTMLButtonElement | null
Type assertions are very error prone, so should be avoided:
screen.queryByText('click me') as HTMLButtonElement; // can still be null!
Suggested implementation:
queryByText<T extends HTMLElement = HTMLElement>(...) => T | null;
Describe alternatives you've considered:
You can do already do something similar with for example querySelector
:
document.body.querySelector<HTMLButtonElement>('.my-button');
Teachability, Documentation, Adoption, Migration Strategy:
Metadata
Metadata
Assignees
Labels
No labels