typescript - 无法使用 TypeScript 将 prop 传递给 svelte 中的组件

标签 typescript svelte

我有一个带有 title 属性的 BigButton 组件

<script lang="ts">
let title: string;
</script>
<h1 class="text-2xl mb-4 font-extrabold">{title}</h1>

然后在我的index.svelte上,我尝试以不同的方式传递 Prop ,但没有一个起作用:

<BigButton title={'Join a Game'} /> <BigButton title='Join a Game' />

lint 给了我以下错误:

Type '{ title: string; }' is not assignable to type 'IntrinsicAttributes'.
  Property 'title' does not exist on type 'IntrinsicAttributes'.

最佳答案

使用应该export它,例如:

export let title: string;

Svelte uses the export keyword to mark a variable declaration as a property or prop, which means it becomes accessible to consumers of the component

关于typescript - 无法使用 TypeScript 将 prop 传递给 svelte 中的组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72831023/

相关文章:

javascript - 如何使 children 不在ag网格中重复( Angular )

typescript - 定义全局 TypeScript 配置(接口(interface)),用于 Aurelia 依赖注入(inject)

ionic-framework - 在 Ios 上使用 Capacitor x Svelte 时按钮响应时间变慢

navigation - Sveltekit 根路由不会导致页面加载

javascript - React Hooks TypeScript 事件和状态类型

@OnCall 和@OnRequest firebase 函数的 typescript 装饰器?

angular - Ag-Grid 编辑数据并发送到服务器

svelte - 如何在 SvelteKit 中以编程方式路由?

svelte - Svelte 过渡/动画是用 CSS 还是 JS 完成的?

svelte - 应该如何使用 load()