API reference › @evolu/common › Type › typeErrorToIssues
function typeErrorToIssues<T>(
type: T,
error: InferErrors<NoInfer>,
): readonly [TypeIssue, TypeIssue];
Defined in: packages/common/src/Type.ts:1005
Converts an error from a Type into formatted issues with paths.
Pass the Type that produced the error. This uses its nested and localized
formatters without validating the input again. To retain every issue, decode
with { errors: "all" }; this function cannot recover errors omitted during
validation. A root issue has an empty path.
Example
import {
assertEqual,
assertErr,
IntFromString,
object,
typeErrorToIssues,
} from "@evolu/common";
const Settings = object({ port: IntFromString });
const result = Settings.fromUnknown({ port: "http" }, { errors: "all" });
assertErr(result);
assertEqual(typeErrorToIssues(Settings, result.error), [
{
path: ["port"],
message: 'The value "http" is not a decimal integer.',
},
]);