我尝试将 flow 与 React 一起使用,但发现了一些奇怪的行为,如果我尝试将 React 中的 HTMLProps 包含到组件 Props 类型中,flow 会抛出错误“无法获取 React.HTMLProps,因为模块 React 中缺少属性 HTMLProps”
\n\n成分:
\n\nconst Row = (\r\n {\r\n jc,\r\n ai,\r\n children,\r\n ...rest\r\n }: RowProps & React.HTMLProps<HTMLDivElement>\r\n) => (\r\n <RowW\r\n justifyContent={jc}\r\n alignItems={ai}\r\n {...rest}>\r\n {children}\r\n </RowW>\r\n)Run Code Online (Sandbox Code Playgroud)\r\n流程错误:
\n\nCannot get React.HTMLProps because property HTMLProps is missing in module react [1].\r\n\r\n [1] 2\xe2\x94\x82 import * as React from \'react\'\r\n :\r\n 21\xe2\x94\x82 ai,\r\n 22\xe2\x94\x82 children,\r\n 23\xe2\x94\x82 ...rest\r\n 24\xe2\x94\x82 }: RowProps …Run Code Online (Sandbox Code Playgroud)我想创建一个可以处理on:click但不导出handleClick函数的组件;这就是现在的运作方式
button.svelte:
<script lang="ts">
export let handleClick: ((e: MouseEvent) => void ) | undefined = undefined
</script>
<button on:click={handleClick}>
<slot></slot>
</button>
Run Code Online (Sandbox Code Playgroud)
app.svelte:
<script lang="ts">
import Button from '$lib/button/button.svelte'
</script>
<Button handleClick={() => console.log('click!')}>
Click me!
</button>
Run Code Online (Sandbox Code Playgroud)
如何更改 Button 元素以on:click直接在应用程序组件中使用?
app.svelte:
<Button on:click={handleClick}>
<slot></slot>
</Button>
Run Code Online (Sandbox Code Playgroud)