diff --git a/lib/compile/errors.ts b/lib/compile/errors.ts index 18d61e917..86565bf8a 100644 --- a/lib/compile/errors.ts +++ b/lib/compile/errors.ts @@ -118,11 +118,11 @@ function errorObjectCode(cxt: KeywordErrorCxt, error: KeywordErrorDefinition): C [E.keyword, keyword], [N.dataPath, strConcat(N.dataPath, errorPath)], [E.schemaPath, str`${errSchemaPath}/${keyword}`], - [E.params, params ? params(cxt) : _`{}`], + [E.params, typeof params == "function" ? params(cxt) : params || _`{}`], ] if (propertyName) keyValues.push([E.propertyName, propertyName]) if (opts.messages !== false) { - const msg = typeof message == "string" ? message : message(cxt) + const msg = typeof message == "function" ? message(cxt) : message keyValues.push([E.message, msg]) } if (opts.verbose) { diff --git a/lib/types/index.ts b/lib/types/index.ts index fdf181a1a..ec15e8677 100644 --- a/lib/types/index.ts +++ b/lib/types/index.ts @@ -159,8 +159,8 @@ export type AddedKeywordDefinition = KeywordDefinition & { } export interface KeywordErrorDefinition { - message: string | ((cxt: KeywordErrorCxt) => Code) - params?: (cxt: KeywordErrorCxt) => Code + message: string | Code | ((cxt: KeywordErrorCxt) => Code) + params?: Code | ((cxt: KeywordErrorCxt) => Code) } export type Vocabulary = (KeywordDefinition | string)[]