Skip to content

[react-autosuggest] update signatures, documentation, use generic type - #21836

Merged
aozgaa merged 4 commits into
DefinitelyTyped:masterfrom
rosskevin:react-autosuggest-updates
Dec 5, 2017
Merged

aozgaa merged 4 commits into
DefinitelyTyped:masterfrom
rosskevin:react-autosuggest-updates

Conversation

@rosskevin

@rosskevin rosskevin commented Nov 29, 2017 •

Copy link
Copy Markdown
Contributor
  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Test the change in your own code. (Compile and run.)
  • Follow the advice from the readme.
  • Avoid common mistakes.
  • Run npm run lint package-name (or tsc if no tslint.json is present).

If changing an existing definition:

Changes

  • 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

- 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
@dt-bot

dt-bot commented Nov 29, 2017

Copy link
Copy Markdown
Member

types/react-autosuggest/index.d.ts

to authors (@nicolas-schmitt @pjo256 @robessog @tbayne @cdeutsch). Could you review this PR?
👍 or 👎?

@rosskevin

Copy link
Copy Markdown
Contributor Author

From previous authors, I need a solid review on this.

All tests succeed locally, but when I try to yarn link this package and use it in my project, I'm seeing

Error:(106, 7) TS2605:JSX element type 'Autosuggest<Language>' is not a constructor function for JSX elements.
  Property 'render' is missing in type 'Autosuggest<Language>'.

I'm new to updating DefinitelyTyped, so I may be missing something.

Certainly though, tsc and lint runs on this PR, just not when I'm trying to use it in my project via yarn link.

@cdeutsch

cdeutsch commented Dec 1, 2017 •

Copy link
Copy Markdown
Contributor

@rosskevin can you share your code where you try to use it?

Sounds like the import statement might be wrong

UPDATE: Maybe checkout this thread
microsoft/TypeScript#3960

I don't have experience with trying to make a generic component like this, so not sure the right way to declare it.

Comment thread types/react-autosuggest/index.d.ts Outdated
import * as React from 'react';

declare class Autosuggest extends React.Component<Autosuggest.AutosuggestProps> {}
declare class Autosuggest<T> extends React.Component<Autosuggest.AutosuggestProps<T>> {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would changing this to declare class Autosuggest<T = any> make this backward compatible?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added, tests work.

};

return <Autosuggest
return <LanguageAutosuggest

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If possible, we should leave this as is to test backward compatibility and duplicate it to test the LanguageAutosuggest version

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Left the ReactAutosuggestBasicTest for backward compatibility, added ReactAutosuggestTypedTest which is identical but strongly typed.

@typescript-bot

Copy link
Copy Markdown
Contributor

@rosskevin Please address comments from the code reviewers.

@typescript-bot typescript-bot added the Revision needed This PR needs code changes before it can be merged. label Dec 1, 2017
@rosskevin

rosskevin commented Dec 1, 2017 •

Copy link
Copy Markdown
Contributor Author

@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 yarn link. I'm inclined to think that my local setup is an environmental problem and that tests are correct, otherwise this would be a big problem for DefinitelyTyped.

Also, changes completed.

@typescript-bot

Copy link
Copy Markdown
Contributor

@cdeutsch - Thanks for your review of this PR! Can you please look at the new code and update your review status if appropriate?

@typescript-bot typescript-bot removed the Revision needed This PR needs code changes before it can be merged. label Dec 1, 2017
Comment thread types/react-autosuggest/index.d.ts Outdated
event: React.FormEvent<any>,
data: SuggestionSelectedEventData<TSuggestion>,
) => void;
type RenderInputComponent<TSuggestion> = (inputProps: InputProps<TSuggestion>) => JSX.Element;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would suggest it will be more correct to use React.ReactNode instead of JSX.Element.

@cdeutsch cdeutsch left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I ran npm run lint react-autosuggest on my machine, against your branch, and didn't get any errors.

Thanks for making those changes 👍

@typescript-bot

Copy link
Copy Markdown
Contributor

Approved by a listed owner. PR ready to merge pending express review by a maintainer.

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.

6 participants