故事书中的打字稿,带有使用参数的道具类型
我有一个组件:
type RowItem<T> = Record<keyof T, any>;
type TableRowsCells<T> = Array<RowItem<T>>;
type TableHeadCells<T> = HeadCell<T>[];
type TableProps<T> = {
ariaLabel: string;
ariaLabelledBy: string;
TableHeadCells: TableHeadCells<T>;
TableRowsCells: TableRowsCells<T>;
defaultOrderBy?: keyof T;
};
function Table<T>(props: TableProps){
// ---------------.
// code stuff.
// ---------------.
}
我正在编写相应的故事书,
import { Story } from '@storybook/react';
export default {
title: 'Table',
component: Table,
};
const Template: Story<TableProps> = (args) => <Table {...args} />;
export const Basic = Template.bind({});
Basic.args = {};
我从故事书中收到错误:
The generic type 'TableProps' requires 1 type argument(s).
我该如何指定?写?宣布?故事书里的论证是这样的吗?
谢谢
I have a component:
type RowItem<T> = Record<keyof T, any>;
type TableRowsCells<T> = Array<RowItem<T>>;
type TableHeadCells<T> = HeadCell<T>[];
type TableProps<T> = {
ariaLabel: string;
ariaLabelledBy: string;
TableHeadCells: TableHeadCells<T>;
TableRowsCells: TableRowsCells<T>;
defaultOrderBy?: keyof T;
};
function Table<T>(props: TableProps){
// ---------------.
// code stuff.
// ---------------.
}
I am writing the corresponding storybook
import { Story } from '@storybook/react';
export default {
title: 'Table',
component: Table,
};
const Template: Story<TableProps> = (args) => <Table {...args} />;
export const Basic = Template.bind({});
Basic.args = {};
I get error from storybook:
The generic type 'TableProps' requires 1 type argument(s).
How can I specify? write? declare? the argument in storybook with this way?
Thx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TableProps 本身是一个泛型类型,因此您需要传递其泛型类型
,例如,下面的代码将
any
指定为TableProps
的泛型类型TableProps is a generic type itself so you need to pass its generic type
for example, the code below specifies
any
asTableProps
's generic type