Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript in storybook with props type using parameter

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

like image 812
Hasina Njaratin Avatar asked Mar 10 '26 19:03

Hasina Njaratin


1 Answers

TableProps is a generic type itself so you need to pass its generic type

for example, the code below specifies any as TableProps's generic type

   const Template: Story<TableProps<any>> = (args) => <Table {...args} />;
like image 143
Hamid Eslami Avatar answered Mar 13 '26 08:03

Hamid Eslami



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!