gajus / table

Formats data into a string table.
Other
894 stars 77 forks source link

SpanningCells API example causes TS error #212

Closed tomhoad closed 1 year ago

tomhoad commented 1 year ago
const data = [
  ['Test Coverage Report', '', '', '', '', ''],
  ['Module', 'Component', 'Test Cases', 'Failures', 'Durations', 'Success Rate'],
  ['Services', 'User', '50', '30', '3m 7s', '60.0%'],
  ['', 'Payment', '100', '80', '7m 15s', '80.0%'],
  ['Subtotal', '', '150', '110', '10m 22s', '73.3%'],
  ['Controllers', 'User', '24', '18', '1m 30s', '75.0%'],
  ['', 'Payment', '30', '24', '50s', '80.0%'],
  ['Subtotal', '', '54', '42', '2m 20s', '77.8%'],
  ['Total', '', '204', '152', '12m 42s', '74.5%'],
];

const config = {
  columns: [
    { alignment: 'center', width: 12 },
    { alignment: 'center', width: 10 },
    { alignment: 'right' },
    { alignment: 'right' },
    { alignment: 'right' },
    { alignment: 'right' }
  ],
  spanningCells: [
    { col: 0, row: 0, colSpan: 6 },
    { col: 0, row: 2, rowSpan: 2, verticalAlignment: 'middle'},
    { col: 0, row: 4, colSpan: 2, alignment: 'right'},
    { col: 0, row: 5, rowSpan: 2, verticalAlignment: 'middle'},
    { col: 0, row: 7, colSpan: 2, alignment: 'right' },
    { col: 0, row: 8, colSpan: 2, alignment: 'right' }
  ],
};

console.log(table(data, config));

Throw the TS error:

TS2345: Argument of type '{ columns: ({ alignment: string; width: number; } | { alignment: string; width?: undefined; })[]; spanningCells: ({ col: number; row: number; colSpan: number; rowSpan?: undefined; verticalAlignment?: undefined; alignment?: undefined; } | { ...; } | { ...; })[]; }' is not assignable to parameter of type 'TableUserConfig'.   Type '{ columns: ({ alignment: string; width: number; } | { alignment: string; width?: undefined; })[]; spanningCells: ({ col: number; row: number; colSpan: number; rowSpan?: undefined; verticalAlignment?: undefined; alignment?: undefined; } | { ...; } | { ...; })[]; }' is not assignable to type 'BaseUserConfig'.     Types of property 'columns' are incompatible.       Type '({ alignment: string; width: number; } | { alignment: string; width?: undefined; })[]' is not assignable to type 'Indexable<ColumnUserConfig>'.         'number' index signatures are incompatible.           Type '{ alignment: string; width: number; } | { alignment: string; width?: undefined; }' is not assignable to type 'ColumnUserConfig'.             Type '{ alignment: string; width: number; }' is not assignable to type 'ColumnUserConfig'.               Type '{ alignment: string; width: number; }' is not assignable to type 'CellUserConfig'.                 Types of property 'alignment' are incompatible.                   Type 'string' is not assignable to type 'Alignment | undefined'.
tomhoad commented 1 year ago

const config: TableUserConfig helped

aditya-manit commented 1 year ago

Did you change anything else ? for me its still the same