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'
}
}
];
Another user suggested I can add as const
to remedy this, but I’d like to avoid this as well. If I remove this, it complains Type 'string' is not assignable to type 'NavIconsName'.(2322)
. Is this unavoidable?
I tried setting as const
or as INavLinkBase<NavIconsName>[]
but I’d like to avoid type assertion if possible.