Skip to content

Field Type Mapping

How PocketBase field types map to TypeScript types.

pbkit maps each PocketBase field type to a TypeScript type. The mapping is used in both Record and Create types.

PocketBase typeTypeScriptNotes
textstring
emailstring
urlstring
editorstringRich text editor content
numbernumber
boolboolean
datestringOr Date with dateStrings: false
select (single)"a" | "b" | "c"Literal union from defined values
select (multi)("a" | "b" | "c")[]Array of literal unions
select (no values, single)stringFallback when no values defined
select (no values, multi)string[]Fallback when no values defined
relation (single)stringThe record ID
relation (multi)string[]Array of record IDs
file (single)stringThe filename
file (multi)string[]Array of filenames
jsonunknown
autodate(excluded)Excluded from Record and Create
password(excluded from Record)Included in Create, excluded from Record

By default, date fields are typed as string (ISO 8601). Set dateStrings: false to use Date:

export default {
types: {
dateStrings: false, // date fields become Date instead of string
},
}

Fields are marked optional (?) based on the PocketBase required setting:

  • Required fields — no ?, must be provided
  • Optional fields — have ?, can be omitted

Override with optionalFields: "all" to make everything optional:

export default {
types: {
optionalFields: "all",
},
}

Add | null to optional fields with nullableFields: true:

export default {
types: {
nullableFields: true,
},
}

This produces:

export type ArticlesRecord = BaseRecord & {
title: string
content?: string | null // optional AND nullable
}