feat: support a function as the error message#10
Merged
Conversation
This was referenced Jun 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add support for passing a function as the
messageof an error definition. The function receives the (typed) params object and returns the message string. The params type for the constructor is inferred from the function's parameter, so you get full type-checking without a{param}template.A zero-argument function behaves like an error without template parameters:
Params type is inferred from the function's first parameter; whether params are required is driven by the function's
arity (number of arguments it expects -
() =>and(params = {}) =>are no-param,(params) =>requires params), keeping the runtime and type levels consistent.Note:
ErrorDefinition's default type parameter widens from string tostring | MessageFnin this release. This is a public type change but is treated as non-breaking —ErrorDefinitionis intended for internal use by this library, and external consumers readingdef.messageas a string would be unusual. Flagging in case anyone depends on it.