我在 Svelte 组件中有以下 HTML 部分:
<div id="result">
<svelte:element this={$tagName} {...$attributes}>{$displayText}</svelte:element>
</div>
根据
tagName
是img
、span
还是button
,将使用不同的$attributes
。这是类型定义:
type Attribute = {
src?: string
styles?: string
}
export const attributes = writable({} as Attribute)
但是,这会产生错误:
输入 '{ src?: string |不明确的;样式?: 字符串 |不明确的; }' 与类型“HTMLAttributes”没有共同的属性。
Copilot 解决方案是从 React 导入,我可以搜索的所有地方都显示
HTMLAttributes
是 React 定义的东西,但这是一个 Svelte 应用程序。这应该如何在 Svelte 中完成?