import React from 'react';
import styled from 'styled-components';
const IconWrapper = styled.Text`
font-family: MyFont;
`;
const glyphs = {
'logo': '\ue94e',
'minus': '\ue900',
'plus': '\ue901',
...
};
interface IconProps {
glyph: string;
}
const Icon: React.FC<IconProps> = ({ glyph }) => {
return (
<IconWrapper>{glyphs[glyph]}</IconWrapper>
);
};
export default Icon;
I need instead of glyph: string pass explicit type enum (or keyof glyphs).
That could be probably enum but I don't want to duplicate the whole structure once again.
Thanks for your ideas
You can use
keyofkeyword combined withtypeofto narrow down the typeFor readability, you can define another type like below :