[英]Typescript in storybook with props type using parameter
我有一个组件:
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).
我该如何指定? 写? 宣布? 用这种方式在故事书中争论?
谢谢
TableProps 本身是一个通用类型,所以你需要传递它的通用类型
例如,下面的代码将any
指定为TableProps
的通用类型
const Template: Story<TableProps<any>> = (args) => <Table {...args} />;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.