This repository was archived by the owner on Jan 10, 2025. It is now read-only.
Add generics to findWhere and findWhereAll in react-testing#1999
Merged
Add generics to findWhere and findWhereAll in react-testing#1999
Conversation
michenly
reviewed
Aug 12, 2021
packages/react-testing/README.md
Outdated
| function Wrapper() { | ||
| return ( | ||
| <> | ||
| <MyComponent name="Michelle" /> |
Member
Author
There was a problem hiding this comment.
The find docs reference you and Gord, I'm just being consistent :p
michenly
reviewed
Aug 12, 2021
packages/react-testing/README.md
Outdated
| (node) => node.is(MyComponent) && node.prop('name').startsWith('M'), | ||
| ); | ||
|
|
||
| const startsWithG = wrapper.findWhere<MyComponent>( |
Contributor
There was a problem hiding this comment.
I am actually a little surprise its wrapper.findWhere<MyComponent> and not wrapper.findWhere<type of MyComponent>, the new version of TS got smarter again?
Member
Author
There was a problem hiding this comment.
Excellent spot, the typeof totally needs to be there
Contributor
There was a problem hiding this comment.
lol it would be so nice if typescript is smart enough in the future to know it should use the typeof in generic
michenly
approved these changes
Aug 12, 2021
Contributor
michenly
left a comment
There was a problem hiding this comment.
🎩 locally with Ben and it looks good to me!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
findWhereandfindAllWherepreviously always returnedElement<unknown>which meant that code didn't know the type of the element returned And thus you got TS errors (forgive this trivial example, where usingfindwould be preferred):This PR adds a generic type to
findWhereand findAllWhere` so that you can specify the type of element that you shall be returning.This generic type is either a string referring to a html element (
'div','form'etc), or a React component (Cardetc). This is the same type as what you can pass intofindas it's first argument.Type of change