Skip to content
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

Improve typings #152

Merged
merged 5 commits into from
Aug 26, 2017
Merged

Improve typings #152

merged 5 commits into from
Aug 26, 2017

Conversation

thomhos
Copy link
Contributor

@thomhos thomhos commented Aug 25, 2017

What:
Minor improvements in typings for getButtonProps, getInputProps, getItemProps.

Why:
When using downshift with typescript and following examples, I've found the get props functions have a lot of optional properties that are marked mandatory in the typings.

How:
I've updated the index.d.ts file and ts test file.

Checklist:

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

@codecov-io
Copy link

codecov-io commented Aug 25, 2017

Codecov Report

Merging #152 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #152   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           4      4           
  Lines         263    263           
  Branches       63     63           
=====================================
  Hits          263    263

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fde301c...4d4986d. Read the comment docs.

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.

Looks pretty good to me. I'd appreciate a review from @pbomb and @vutran 👍

@@ -49,7 +53,7 @@ export default class App extends React.Component<Props, State> {
)
.map((item: any, index: number) =>
<div
{...getItemProps({ item, index })}
{...getItemProps({ item, index, isSelected: selectedItem === item })}
Copy link
Member

Choose a reason for hiding this comment

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

This is going to put an attribute on the div called isSelected. I realize this is just a test, but it's probably best to make sure that the test code is correct 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, we may want to remove user-defined props from the basic test. Perhaps a secondary test for cases like this would work?

Copy link
Collaborator

Choose a reason for hiding this comment

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

isSelected is not a valid DOM element prop, so would generate a warning from React, right? Tests shouldn't generate React warnings, so if this would, I think it would be better off removed.

I'm new to downshift and trying to understand why getItemProps returns any key/value pairs it doesn't recognize. In this example, it would be easy enough to get the same behavior using this code:

                                         <div
                                              {...getItemProps({ item, index })}
                                              isSelected={selectedItem === item}

Is there a different scenario where this approach is not possible and props need to be passed through getItemProps? If not, then why return ...rest inside that function?

Copy link
Contributor

@morajabi morajabi Aug 25, 2017

Choose a reason for hiding this comment

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

I think @pbomb's question is right.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a new test that shows the above with a custom component for a list item. Adding isSelected separately is also possible, but since the ...rest is in the js, I figured to have the typings reflect that as well.

"name": "thom",
"avatar_url": "https://avatars1.githubusercontent.com/u/11661846?v=4",
"profile": "http://thom.kr",
"contributions": []
Copy link
Contributor

Choose a reason for hiding this comment

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

Mind adding me too (if it's okay with @kentcdodds)? I had forgotten to add myself to this list. 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

Copy link
Collaborator

@pbomb pbomb left a comment

Choose a reason for hiding this comment

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

Looks good to me. I'm not sure why getItemProps returns unrecognized key-value pairs back to the caller, but that's outside the scope of this pull request (and likely has good reasoning).

@kentcdodds kentcdodds merged commit 3a78ff7 into downshift-js:master Aug 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants