Repository navigation
[react-autosuggest] update signatures, documentation, use generic type - #21836
Conversation
- Convert Autosuggest component to a generic - Update the renderSuggestionsContainer signature - Add readme with usage example - Document component props - Export function types for easier reuse/passing in as props
|
types/react-autosuggest/index.d.ts to authors (@nicolas-schmitt @pjo256 @robessog @tbayne @cdeutsch). Could you review this PR? |
|
From previous authors, I need a solid review on this. All tests succeed locally, but when I try to I'm new to updating DefinitelyTyped, so I may be missing something. Certainly though, |
|
@rosskevin can you share your code where you try to use it? Sounds like the UPDATE: Maybe checkout this thread I don't have experience with trying to make a generic component like this, so not sure the right way to declare it. |
| import * as React from 'react'; | ||
|
|
||
| declare class Autosuggest extends React.Component<Autosuggest.AutosuggestProps> {} | ||
| declare class Autosuggest<T> extends React.Component<Autosuggest.AutosuggestProps<T>> {} |
There was a problem hiding this comment.
Would changing this to declare class Autosuggest<T = any> make this backward compatible?
There was a problem hiding this comment.
Added, tests work.
| }; | ||
|
|
||
| return <Autosuggest | ||
| return <LanguageAutosuggest |
There was a problem hiding this comment.
If possible, we should leave this as is to test backward compatibility and duplicate it to test the LanguageAutosuggest version
There was a problem hiding this comment.
Left the ReactAutosuggestBasicTest for backward compatibility, added ReactAutosuggestTypedTest which is identical but strongly typed.
|
@rosskevin Please address comments from the code reviewers. |
|
@cdeutsch regarding the imports I had already read that and I linked to the ultimate result of it in the README that I added. It works fine in tests, so not sure why I have a problem with Also, changes completed. |
|
@cdeutsch - Thanks for your review of this PR! Can you please look at the new code and update your review status if appropriate? |
| event: React.FormEvent<any>, | ||
| data: SuggestionSelectedEventData<TSuggestion>, | ||
| ) => void; | ||
| type RenderInputComponent<TSuggestion> = (inputProps: InputProps<TSuggestion>) => JSX.Element; |
There was a problem hiding this comment.
I would suggest it will be more correct to use React.ReactNode instead of JSX.Element.
|
Approved by a listed owner. PR ready to merge pending express review by a maintainer. |
npm run lint package-name(ortscif notslint.jsonis present).If changing an existing definition:
tslint.jsoncontaining{ "extends": "dtslint/dt.json" }.Changes
renderSuggestionsContainersignature