IErrorDetail should be exported
mrzap0 opened this issue · 4 comments
mrzap0 commented
It is currently not possible to pass an IErrorDetail value to another function without downgrading it to any.
eg.
import { Checker } from "ts-interface-checker";
export function implementsInterface(typeName: string, checker: Checker, value: any): boolean {
const result = checker.validate(value);
if (result === null) {
return true;
} else {
console.error(`ERROR: Value does not implement '${typeName}':\n${formatCheckerError(result)}`);
return false;
}
}
function formatCheckerError(error: any /* IErrorDetail not exported from ts-interface-checker */, prefix = '\n '): string {
let s = `${error.path} ${error.message`;
if (error.nested) {
for (const nested in error.nested) {
s += prefix + formatCheckerError(nested, prefix + ' ');
}
}
return s;
}
zenflow commented
@mrzap0 A workaround for now is to import { IErrorDetail } from 'ts-interface-checker/dist/util'
, but careful when you upgrade the package, because this internal file can change or be moved.
dsagal commented
This is fixed in v0.1.12.
mrzap0 commented
Confirmed