diontools/ts-json-checker

Support index signature

Opened this issue · 0 comments

config:

interface IndexSigType {
    [key: string]: number
}

json:

{
    "a": 1,
    "b": 2
}

check:

function check(v: any, r: string) {
    for (const key of Object.keys(v)) {
        if (typeof v[key] === "number") {}
        else
            throw new TypeError(r + "." + key + " is not Number.")
    }
}