cli-table3 icon indicating copy to clipboard operation
cli-table3 copied to clipboard

[Bug/Question] Cross tables typing

Open Xaz16 opened this issue 5 years ago • 2 comments

Problem:

This code snippet produce such error from Typescript:

const resultTable = new Table({
  head: ['', 'Assets ', 'Entries']
});

resultTable.push(
   { 'Previous values': [`100`, `200`] },
   { 'Normalized values': [`10`, `100`] }
);
Type 'string[]' is not assignable to type '(string & Cell[]) | (number & Cell[]) | (false & Cell[]) | (true & Cell[]) | (CellOptions & Cell[])'.
  Type 'string[]' is not assignable to type 'CellOptions & Cell[]'.
    Property 'content' is missing in type 'string[]' but required in type 'CellOptions'.ts(2322)

According to the documentation about cross table this code should be absolutely valid https://github.com/cli-table/cli-table3#cross-tables.

Could you check the typing for that case or maybe I'm wrong?

Environment

Typescript: 3.8.3 cli-table3: 0.6.0

Xaz16 avatar Oct 15 '20 09:10 Xaz16

From the syntax in your table, it seems your table is not correct. Each row pushed into the table is expected to be an array of cells. You're pushing objects into the table.

Try this instead:

resultTable.push(
   ['Previous values:', 100, 200],
   ['Normalized values:', 10, 100],
);

speedytwenty avatar Mar 27 '22 17:03 speedytwenty

I wasn't aware of the "cross-table" syntax option mentioned here: https://github.com/cli-table/cli-table3#cross-tables

Reopening. I'll take another poke at this now that my incorrect assumption is corrected.

speedytwenty avatar Mar 27 '22 17:03 speedytwenty