我想使用动态组件根据枚举的值选择视图:
<svelte:component
this={components[enumValue]}
{...props}
/>
Run Code Online (Sandbox Code Playgroud)
但如果我不传递所有必要的参数,我不会收到编译错误:
<svelte:component
this={components[enumValue]}
/>
Run Code Online (Sandbox Code Playgroud)
如何正确指定动态组件的类型?
UPD:React 的地图示例
const props: Props = {...}
const components: Record<EnumType, React.FC<Props>> = {
[EnumType.variant_1]: Component1,
[EnumType.variant_2]: Component2,
}
Run Code Online (Sandbox Code Playgroud)