gristlabs/ts-interface-checker

IErrorDetail should be exported

mrzap0 opened this issue · 4 comments

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;
}

I think #27 would fix it. I was waiting for some feedback, but will merge in soon.

@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.

This is fixed in v0.1.12.

Confirmed