feat: export types for icon names
does this pr fix this https://github.com/oblador/react-native-vector-icons/issues/1760, and update the glyphmaps file
@vonovak thanks!
Instead of doing export type FontAwesome5ProLightIconName = keyof typeof lightGM; can't we do export type FontAwesome5ProLightIconName = ComponentProps<typeof LightIcon>['name'];
This is just a suggestion as the types exported are still not useful if we are creating a reusable component which renders the icon by accepting the icon name as prop to that component. In this case FontAwesome5ProLightIconName = ComponentProps<typeof LightIcon>['name']; works well.
hello,
Instead of doing export type FontAwesome5ProLightIconName = keyof typeof lightGM; can't we do export type FontAwesome5ProLightIconName = ComponentProps<typeof LightIcon>['name'];
Those are the same thing. They are equivalent. Not sure I understand what you have in mind?
@vonovak What I mean is, with the current implementation i.e export type FontAwesome5ProSolidIconName = keyof typeof solidGM; when I do the following I faced type errors.
import FontAwesome5Pro, {
FontAwesome5ProSolidIconName,
} from '@react-native-vector-icons/fontawesome5-pro';
const IconComponent = ({
name,
size = 24,
color = '#000',
}: {
size: number;
color: string;
name: FontAwesome5ProSolidIconName;
}) => (
<FontAwesome5Pro
name={name} // This line throws type error "Type 'string | number | symbol' is not assignable to type
// '"function" | "font-awesome-logo-full" ... 2296 more ... | "zhihu"'
size={size}
color={color}
iconStyle={'solid'}
/>
);
const IconComponentExample = () => (
<IconComponent name='home' size={30} color='#000' />
);
export default IconComponentExample;
This error goes away when I do export type FontAwesome5ProSolidIconName = ComponentProps<typeof SolidIcon>['name'];. I hope this helps
@abitling master has a fix and new release coming shortly
@abitling master has a fix and new release coming shortly
@johnf Thank you 🙏🏻