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

Add typescript typings for Icon names. #1475

Closed
nandorojo opened this issue Nov 15, 2019 · 5 comments
Closed

Add typescript typings for Icon names. #1475

nandorojo opened this issue Nov 15, 2019 · 5 comments

Comments

@nandorojo
Copy link

Describe the feature

Big fan of this awesome library. This is a small suggestion.

If you give an icon an invalid name, you get an error telling you all of the available icon names:

<Button icon="some-inexistent-name"></Button>

// Invalid prop `name` of value `some-inexistent-name` supplied to `Icon`

Screen Shot 2019-11-14 at 9 19 30 PM

It would be useful if the icon prop had Typescript suggestions with the available names.

Also, in the error message, it would be useful to add a link to a website that has the available icon names.

Motivation

It's hard to know which icon types are usable while coding. Also, the error message is long, so it slows the logs down a little.

Related Issues

@jayu
Copy link
Contributor

jayu commented Nov 29, 2019

It's currently impossible to statically type icon name since the actual Icon component is defined in runtime. The best way you can achieve it now is to override types for a particular paper component, assuming that you have a list of all icon names. Paper uses material-vector-icons by default.

// MyIconButton.ts
import { IconButton } from 'react-native-paper'

type IconButtonProps = React.ComponentProps<typeof IconButton> & { icon : 'icon1' | 'icon2' | ...}

export default IconButton as React.ComponentType<IconButtonProps>

@jayu
Copy link
Contributor

jayu commented Nov 29, 2019

@nandorojo Could you please add a comment in this thread regarding the typing icon prop? #1489
Then we could try to find a solution for that in 4.0

@nandorojo
Copy link
Author

Definitely! Thanks for your attention here.

@github-actions
Copy link

Hello 👋, this issue has been open for more than 2 months with no activity on it. If the issue is still present in the latest version, please leave a comment within 7 days to keep it open, otherwise it will be closed automatically. If you found a solution on workaround for the issue, please comment here for others to find. If this issue is critical for you, please consider sending a pull request to fix the issue.

@github-actions github-actions bot added the Stale label Feb 11, 2020
@Trancever Trancever removed the Stale label Feb 11, 2020
@github-actions
Copy link

Hello 👋, this issue has been open for more than 2 months with no activity on it. If the issue is still present in the latest version, please leave a comment within 7 days to keep it open, otherwise it will be closed automatically. If you found a solution on workaround for the issue, please comment here for others to find. If this issue is critical for you, please consider sending a pull request to fix the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants