ValibotのIssue
全propertyに対して説明がある
code:ts
type BaseIssue = {
// 必須情報
kind: 'schema' | 'validation' | 'transformation';
type: string;
input: unknown;
expected: string | null;
received: string;
message: string;
// 任意情報
requirement?: unknown;
path?: IssuePath;
issues?: Issues;
lang?: string;
abortEarly?: boolean;
abortPipeEarly?: boolean;
skipPipe?: boolean;
};
.pathがあるの便利そうだmrsekut.icon
zodはpathが不明なので、leafなschemaに対するerrorがどこで起きたのか分かりづらかった
これでpathを作れる
code:ts
const dotPath = issue.path.map((item) => item.key).join('.');
code:ts
import * as v from 'valibot';
const ObjectSchema = v.object({
key: v.string('Value of "key" is missing.'),
nested: v.object({
key: v.string('Value of "nested.key" is missing.'),
}),
});
const result = v.safeParse(ObjectSchema, { nested: {} });
if (result.issues) {
console.log(v.flatten<typeof ObjectSchema>(result.issues));
}