小编nyx*_*nyx的帖子

作为对象属性的 Svelte 组件

我想接受一个组件作为道具。

import AComponent from './AComponent.svelte';

type MyType = {
  [key: string]: any; // just an example
}

type IWantToAcceptAComponent<T> = {
  component: SvelteComponentTyped<{ record: T }>;
}

const componentPropObject: IWantToAcceptAComponent<MyType> = {
  component: AComponent // error here
}
Run Code Online (Sandbox Code Playgroud)
Error: Type 'typeof AComponent__SvelteComponent_' is missing the following properties from type 
'SvelteComponentTyped<{ record: MyType; }>': $set, $on, $destroy, $$prop_def, and 5 
more.ts(2740)
Run Code Online (Sandbox Code Playgroud)

我认为 typedef 可能应该是:

Error: Type 'typeof AComponent__SvelteComponent_' is missing the following properties from type 
'SvelteComponentTyped<{ record: MyType; }>': $set, $on, …
Run Code Online (Sandbox Code Playgroud)

typescript typescript-generics svelte

5
推荐指数
2
解决办法
4982
查看次数

标签 统计

svelte ×1

typescript ×1

typescript-generics ×1