keyring() field, an optional() wrapper, a nested object, or a single-element array. You pass the schema to defineConfig() once at module level, and tauri-plugin-configurate derives all TypeScript types from it automatically. You never have to write the config interface by hand.
defineConfig(schema)
Validates and freezes a schema object at runtime. The return value is the same object you passed in —defineConfig() exists so TypeScript can infer the generic parameter S and propagate it into every downstream type.
A plain object where each value is a primitive constructor (
String, Number, Boolean), a keyring() field, an optional() field, a nested schema object, or a single-element array like [String]. Arrays must contain exactly one element.The same schema object passed in, typed as
S. Assign the return value to a const so that TypeScript treats it as a literal type rather than a widened one.defineConfig() performs two checks and throws on failure:
- Every schema array (
[String],[Number], etc.) must contain exactly one element. - Every
keyring()id within the schema must be unique.
TypeScript enforces unique keyring IDs at the type level via
HasDuplicateKeyringIds<S>. If you accidentally reuse an ID, the TypeScript compiler rejects the call before it reaches the runtime check.keyring(typeCtor, opts)
Marks a schema field as OS keyring-protected. The value is stored in the operating system’s credential store (not in the config file) and is returned asnull when loading without an unlock step.
The JavaScript constructor function for the value’s type:
String, Number, or Boolean.Unique identifier for this keyring entry within the schema. Must not be empty. Must not contain
/ — the slash is used as a separator in the keyring user string ({account}/{id}), so including it would create an ambiguous path.A branded marker object. At runtime this object is a plain record with internal brand keys; its shape matters only to the plugin internals and the TypeScript type system.
optional(schema)
Wraps any schema value to mark it as optional. An optional field may be absent from the stored config; it does not fail schema validation when missing, and its inferred TypeScript type includes| undefined.
Any valid schema value: a primitive constructor, a
keyring() field, a nested schema object, or a single-element array. You cannot nest optional() inside another optional().A branded marker object that wraps
schema and signals optionality to the type inference utilities and runtime validation.Schema types reference
The table below shows every schema value type and the TypeScript type it produces throughInferUnlocked<S> and InferLocked<S>.
| Schema value | InferUnlocked<S> | InferLocked<S> |
|---|---|---|
String | string | string |
Number | number | number |
Boolean | boolean | boolean |
keyring(String, ...) | string | null |
keyring(Number, ...) | number | null |
keyring(Boolean, ...) | boolean | null |
optional(String) | string | undefined | string | undefined |
optional(keyring(String, ...)) | string | undefined | null | undefined |
{ key: String } | { key: string } | { key: string } |
[String] | string[] | string[] |
[keyring(String, ...)] | string[] | null[] |
Type inference utilities
Two utility types let you reference the inferred config shape in your own code:InferUnlocked<S>
Produces the full config type with all keyring fields resolved to their real value types. Use this when you have an unlocked config or when constructing data to pass tocreate(), save(), or reset().
InferLocked<S>
Produces the config type with all keyring fields replaced bynull. This is the type of LockedConfig<S>.data — what you see when you call load().run() without unlocking.