Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions src/type-system/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,32 @@ export type TForm<T extends TProperties = TProperties> = TUnsafe<
ElysiaFormData<TObject<T>['static']>
>

export type ElysiaTypeCustomError =
| string
| boolean
| number
| ElysiaTypeCustomErrorCallback
/**
* Augment this interface to extend allowed values for SchemaOptions['error'].
* Defining custom string templates will add autocomplete while allowing any arbitrary string, number, etc.
*
* The names of keys only used to map to the values, unless you globally augment a specific key.
*
* ```ts
* declare module 'elysia/type-system/types' {
* interface ElysiaTypeCustomErrors {
* myPlugin: 'my.plugin.error' | `my.plugin.${string}`
* }
* }
*
* const schema = t.String({ error: 'my.plugin.hello' })
* ```
*/
export interface ElysiaTypeCustomErrors {
/**
* The default error types that the library supports.
*
* `string & {}` `number & {}` are used to allow string templates and numbers respectively.
*/
default: (string & {}) | boolean | (number & {}) | ElysiaTypeCustomErrorCallback
}

export type ElysiaTypeCustomError = ElysiaTypeCustomErrors[keyof ElysiaTypeCustomErrors]

export type ElysiaTypeCustomErrorCallback = (
error: {
Expand Down