How to retreive Error metadata

Hi! I'm creating an error using Arktype and I want to attach metadata so I can format the message later in my UI (React + react-hook-form):
return ctx.reject({
message: "errorKey",
meta: { variableName: "name" } as any,
path: ["path"],
});
return ctx.reject({
message: "errorKey",
meta: { variableName: "name" } as any,
path: ["path"],
});
My problem is that i have to add "as any" to metadata. I found this for type metadata https://arktype.io/docs/configuration#metadata but couln't quite identify which interface i need to override in my case. Did anyone encounter this issue before? Thank you!
ArkType
ArkType Docs
TypeScript's 1:1 validator, optimized from editor to runtime
1 Reply
ssalbdivad
ssalbdivad5d ago
Hey! If react-hook-form provides a metadata type that represents what they're interested in (or if you define one yourself), you should be able to extend ArkEnv's metadata to include it like this:
declare global {
interface ArkEnv {
meta(): Partial<ReactHookFormMeta>
}
}
declare global {
interface ArkEnv {
meta(): Partial<ReactHookFormMeta>
}
}
However, in testing this I notice a bug where custom user metadata is not available in the ctx.reject API. This will be fixed in the next release so you can stop casting! Feel free to open a github issue if you'd like it tracked

Did you find this page helpful?