Types
Use x.row() to define the types for the schema you pass to CSVImporter. Each field controls:
- How uploaded values are parsed and validated
- Labels shown in the importer
- TypeScript types before rows reach your app
Schema package in a monorepo
In a monorepo:
- Keep row definitions in a dedicated
typesorschemaspackage (for examplepackages/schemas) that your apps import - Use @expresscsv/schemas when you only need schema helpers and do not want the importer code in your dependencies
Basic Usage
Each key becomes a column the user maps to. The field type determines how values are parsed and validated before your delivery callback runs.
Shared Field Behavior
These methods work the same way across field types:
.optional()lets the importer accept an empty cell for that field. Empty optional values are delivered asnull, and the row object still includes the schema key..default(value)is available after.optional(). It is used when the imported value is empty, including missing values,null, an empty string, or whitespace. When a default is used, it is returned directly instead of running the empty value through the rest of the field validators..columnNameAliases([...])adds extra header names for column matching. Aliases are used alongside the field key and label by deterministic matching, managed AI matching, and custom matching.
Field Types
- String -
x.string() - Number -
x.number() - Boolean -
x.boolean() - Date -
x.date() - Time -
x.time() - Datetime -
x.datetime() - Select -
x.select() - Multiselect -
x.multiselect()
Custom Validation
Use Refine for custom validators with .refine(), .refineBatch(), and suggested fixes.
Dynamic Schemas
You can build the schema conditionally before constructing CSVImporter:
If you use dynamic elements while assembling a schema, Infer<typeof schema> can widen because the exact keys are no longer guaranteed at compile time.
Use dynamic schema assembly intentionally when you need runtime-driven columns.
TypeScript Inference
Use Infer<typeof schema> to extract the validated row type from your schema: