Skip to content

CONSUME-AS-DATA-04: Iterate a TableView's typed rows

A section whose sole content is a table promotes to a TableView you iterate as typed rows.

Builds on: CONSUME-AS-DATA-03: Walk a SectionView’s content surface

A TypeScript program against the library API; inline comments show the resulting values and behavior.

const c = contract({ body: sections({}, [
section("Files", { content: table({
columns: ["File", "Kind", "Location"],
cells: { Kind: z.enum(["add", "modify", "delete"]) },
}) }),
])});
const files = c.read(src, { path: "task.md" }).body.files; // promoted TableView
for (const row of files) console.log(row.File, row.Kind); // row.Kind is the enum union
console.log(files.rowCount, files.columns);
  • section() content: table()
  • TableView promotion
  • iteration over typed rows
  • .rowCount
  • .columns