Skip to Content
@jetio/schema-builder docs are live πŸŽ‰
Type InferencePattern Properties

Pattern Properties

Regex patterns map directly to TypeScript template literals β€” ^user_ becomes `user_${string}` β€” giving type-safe dynamic keys with no extra work.

Basic pattern properties

const configSchema = new SchemaBuilder() .object() .properties({ appName: (s) => s.string() }) .patternProperties({ "^env_": (s) => s.string(), // properties starting with "env_" "^feature_": (s) => s.boolean(), // properties starting with "feature_" "_id$": (s) => s.number(), // properties ending with "_id" }) .required(["appName"]) .build(); type Config = Jet.Infer<typeof configSchema>; // { // appName: string; // [key: `env_${string}`]: string; // [key: `feature_${string}`]: boolean; // [key: `${string}_id`]: number; // }

Supported pattern types

// Prefix with separator "^data_" β†’ `data_${string}` "^api-" β†’ `api-${string}` "^config." β†’ `config.${string}` // Prefix without separator "^user" β†’ `user${string}` // Suffix with separator "_id$" β†’ `${string}_id` "-name$" β†’ `${string}-name` ".json$" β†’ `${string}.json` // Suffix without separator "Type$" β†’ `${string}Type` // Infix (contains separator) "_" β†’ `${string}_${string}` "-" β†’ `${string}-${string}` "." β†’ `${string}.${string}` // Wildcards and complex patterns fall back to string ".*" β†’ string "^[a-zA-Z].*" β†’ string ".*[0-9]$" β†’ string

Complex regex like ^[a-z]{3,5}$ or \d+ fall back to string. Only common, simple patterns convert to template literals.

Last updated on