-
Notifications
You must be signed in to change notification settings - Fork 933
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
Types 1.2.0 #165
Types 1.2.0 #165
Conversation
These props are not required for getButtonProps.
Allow null in places where the docs say they can go. Add missing `itemCount` property.
Codecov Report
@@ Coverage Diff @@
## master #165 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 4 4
Lines 267 267
Branches 64 64
=====================================
Hits 267 267 Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks awesome to me! I'd love a review from some other folks though...
typings/index.d.ts
Outdated
@@ -1,25 +1,28 @@ | |||
import * as React from 'react'; | |||
|
|||
type CB = () => void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The callbacks are optional. Additionally, the code checks if they are functions and only returns them if they are. So, I think it would be more correct to go with either Function | undefined
or () => any | undefined
. I think void
is too restrictive - we don't really care what the callback function returns.
The TypeScript types for React's setState
function (which is how these callbacks are used) is typed as () => any | undefined
typings/index.d.ts
Outdated
defaultSelectedItem?: any; | ||
defaultInputValue?: string; | ||
defaultIsOpen?: boolean; | ||
getA11yStatusMessage?: (options: A11StatusMessageOptions) => any; | ||
itemToString?: (item: any) => string; | ||
onChange?: (selectedItem: any, stateAndHelpers: ControllerStateAndHelpers) => void; | ||
onStateChange?: (options: StateChangeOptions, stateAndHelpers: ControllerStateAndHelpers) => void; | ||
onStateChange?: (changes: StateChangeOptions, stateAndHelpers: ControllerStateAndHelpers) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to keep this named as options
to be consistent with everything else in here.
typings/index.d.ts
Outdated
openMenu: (cb: CB) => void; | ||
closeMenu: (cb: CB) => void; | ||
toggleMenu: (cb: CB) => void; | ||
selectItem: (item: any, otherStateToSet: any, cb: CB) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
otherStateToSet
and cb
should be optional types. Additionally, if otherStateToSet
is defined, it should be an object as it gets spread into another object.
typings/index.d.ts
Outdated
closeMenu: (cb: CB) => void; | ||
toggleMenu: (cb: CB) => void; | ||
selectItem: (item: any, otherStateToSet: any, cb: CB) => void; | ||
selectItemAtIndex: (index: number, otherStateToSet: any, cb: CB) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
otherStateToSet
and cb
should be optional types. Additionally, if otherStateToSet
is defined, it should be an object as it gets spread into another object.
typings/index.d.ts
Outdated
toggleMenu: (cb: CB) => void; | ||
selectItem: (item: any, otherStateToSet: any, cb: CB) => void; | ||
selectItemAtIndex: (index: number, otherStateToSet: any, cb: CB) => void; | ||
selectHighlightedItem: (otherStateToSet: any, cb: CB) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
otherStateToSet
and cb
should be optional types. Additionally, if otherStateToSet
is defined, it should be an object as it gets spread into another object.
typings/index.d.ts
Outdated
selectItem: (item: any, otherStateToSet: any, cb: CB) => void; | ||
selectItemAtIndex: (index: number, otherStateToSet: any, cb: CB) => void; | ||
selectHighlightedItem: (otherStateToSet: any, cb: CB) => void; | ||
setHighlightedItem: (index: number, otherStateToSet: any, cb: CB) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
otherStateToSet
should be optional and there is no cb
argument to this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you talking about setHighlightedItem
here? If so, I think that, first of all, this must be a typo; I just noticed that setHighlightedItem
is not in the docs. However, there is setHighlightedIndex
. If that is the case, I believe it does have a cb
argument:
setHighlightedIndex | function(index: number, otherStateToSet: object, cb: Function) | call to set a new highlighted index |
---|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I was talking about setHighlightedItem
, but now I don't see it anywhere in the repo except in the TypeScript definitions, so I think you can remove this line.
As for the line above, with selectHighlightedItem
, you're right. otherStateToSet
should be optional and there is also an optional cb
argument.
typings/index.d.ts
Outdated
selectItemAtIndex: (index: number, otherStateToSet: any, cb: CB) => void; | ||
selectHighlightedItem: (otherStateToSet: any, cb: CB) => void; | ||
setHighlightedItem: (index: number, otherStateToSet: any, cb: CB) => void; | ||
clearSelection: (cb: CB) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cb
is optional
typings/index.d.ts
Outdated
selectHighlightedItem: (otherStateToSet: any, cb: CB) => void; | ||
setHighlightedItem: (index: number, otherStateToSet: any, cb: CB) => void; | ||
clearSelection: (cb: CB) => void; | ||
reset: (otherStateToSet: any, cb: CB) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cb
is optional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is otherStateToSet
also optional here?
@pbomb First of all, thanks for reviewing the PR! I have a local commit with the changes, but I'm waiting to push until we resolve my two follow-up questions. Also, do you have any thoughts on my additional comments (in the original PR post)? If you think any of those are worth doing, we can also do them in this branch so that it all gets merged in on one go. |
* Rename `changes` back to `options`. * Add optional arguments in the right places. * Use `Function` as type for `cb`. * Use `object` ast type for `otherStateToSet`. * Fix incorrect name `setHighlightedItem` by changing it to `setHighlightedIndex`.
@tansongyang sorry, i missed your questions in the initial PR posting. Here's what my thoughts are.
|
That's a mistake actually. We should remove the prop. It's undocumented so I don't think we need a breaking change for it. Sorry about that! |
* Rename `A11StatusMessageOptions` to `A11yStatusMessageOptions`. * Remove `ChangeOptions`. * Remove `onClick` prop.
I've made the changes that we discussed. Let me know if anything else needs to change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great. Thanks @tansongyang!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much!
There are merge conflicts. Could you fix them? Thanks! |
@kentcdodds Thanks for getting that README merge conflict! It was a pleasure working with you all. |
You're welcome! The build is broken right now due to a problem with TypeScript. Could someone look into that please? |
I'm taking a look now |
Found the issue. After I removed |
In my local environment, I believe I've fixed the TS issue, as it now successfully compiles. However, Also, the problem in the test files was |
Go ahead and fix whatever you can and I'll fix what's left. Thanks! |
New pull request: #175 Apologies for the inconvenience. Thanks for being flexible. |
What: Update typings.
Why: Some types did not match the docs.
How: Edit index.d.ts
Checklist:
I tried to make only non-breaking changes (adding types, making required types optional, etc.) with one exception.
GetButtonPropsOptions
was requiring incorrect properties—in fact, it shouldn't be requiring any at all. I completely removed them.There are a couple things that probably should change, but I didn't want to make them for fear of introducing a breaking change. These are:
onUserAction
andonClick
inDownshiftProps
are not in the docs. Have they been removed? If so, they should be removed from the type definitions as well.A11StatusMessageOptions
should probably be renamed toA11yStatusMessageOptions
(there is a missing "y")ChangeOptions
is completely unused, and I could not find any mention of it in the docs. However, it is exported, so I did not remove it in case anyone is importing it.