Add ability for users to supply generic type#258
Add ability for users to supply generic type#258samtsai wants to merge 1 commit intotesting-library:mainfrom
Conversation
|
Not sure who maintains this project but wanted to get some 👀 on this PR |
|
I'm not sure I'm in favor of this change. This is one of those situations where you're letting the compiler lie to you. I would much rather you add a type guard ( |
Yea I'm glad you called it out. I was following the pattern in Cypress itself but actual type guards would be useful. Let me consider this more. It's also the same way we define it in DOM Testing Library: Adding type guards as far as I can tell will require an API change to all the queries, something like this looks appealing: https://effectivetypescript.com/2020/07/27/safe-queryselector/ Still researching but haven't found many great examples in the wild, maybe because it's sort of straightforward? |
What:
Add ability to supply generic types similar to Cypress's API
Why:
This allows for further narrowing elements returned by queries in tests instead of just
HTMLElementfor every elementHow:
Update types to include generic
<E extends Node = HTMLElement>Ran
npx dslint typeslocally and validated ExpectType tests still passedChecklist: