export type NavIconsName =
| 'home-filled'
| 'home-regular'
| 'folder-filled'
| 'folder-regular';
export interface INavLinkBase<T = {}> {
linkName: string;
svgIcon?: ISvgIconProps<T>;
selectedSvgIcon?: ISvgIconProps<T>;
}
export interface ISvgIconProps<IconType> {
iconName: IconType;
}
const shouldAddLink = true;
const navLinks: INavLinkBase<NavIconsName>[] = [
...(shouldAddLink ? ([
{
linkName: 'test4',
svgIcon: {
iconName: 'folder-regular'
}
}
]) as const: []),
{
linkName: 'test',
svgIcon: {
iconName: 'folder-regular'
},
selectedSvgIcon: {
iconName: 'folder-filled'
}
}
];
There was a suggestion to use as const
to fix this issue, but I am hesitant to take that route. When I attempted to remove it, I received the error message
Type 'string' is not assignable to type 'NavIconsName'.(2322)
. Is there any alternative solution to this problem?
Even though I experimented with using as const
or
as INavLinkBase<NavIconsName>[]
, I would prefer to avoid type assertion if there is another option available.