Typed-xlsx
Schema Builder

Build Schema

Finalizing a schema with .build() and reusing it across multiple workbooks.

Finish your schema with .build().

import { 
createExcelSchema
} from "@chronicstone/typed-xlsx";
const
schema
=
createExcelSchema
<{
firstName
: string;
lastName
: string }>()
.
column
("firstName", {
accessor
: "firstName" })
.
column
("lastName", {
accessor
: "lastName" })
.
build
();

Calling .build() freezes the builder output into a plain schema definition that can be reused across:

  • several buffered workbooks
  • several stream exports
  • different column selections
  • different sheet layouts

In practice, this is the schema object you pass into .table({ schema, ... }).

The schema type carries all declarations

The returned SchemaDefinition type is generic over your row type, all column IDs, all group IDs, and all group context shapes. Nothing is erased by .build():

import { 
createExcelSchema
} from "@chronicstone/typed-xlsx";
import type {
SchemaColumnId
,
SchemaGroupId
,
SchemaGroupContext
} from "@chronicstone/typed-xlsx";
type
User
= {
name
: string;
email
: string;
orgs
: number[] };
const
schema
=
createExcelSchema
<
User
>()
.
column
("name", {
accessor
: "name" })
.
column
("email", {
accessor
: "email" })
.
group
("orgIds", (
b
,
ids
: number[]) => {
for (const
id
of
ids
)
b
.
column
(`org-${
id
}`, {
accessor
: (
r
) =>
r
.
orgs
.
includes
(
id
) });
}) .
build
();
type
Columns
=
SchemaColumnId
<typeof
schema
>;
type
Groups
=
SchemaGroupId
<typeof
schema
>;
type
Context
=
SchemaGroupContext
<typeof
schema
>;

Passing this schema to .table() constrains:

  • rows to User[]
  • select.include and select.exclude to "name" | "email" | "orgIds"
  • context to { orgIds: number[] } when the orgIds group is selected
Copyright © 2026 Cyprien Thao. Released under the MIT License.