mojotech / json-type-validation

TypeScript JSON type validation
MIT License
155 stars 14 forks source link

Possible to validate hash table of arbitrary length? #51

Closed Joncom closed 4 years ago

Joncom commented 4 years ago

Is this library able to validate a hash table with arbitrary keys, yet consistent value types?

For example:

type Example = {
    a: string,
    b: number,
    c: { [name: string]: number }
};

Can c be validated to ensure the keys are strings and the values are numbers, even though the keys are not explicitly declared?

const exampleDecoder: Decoder<Example> = object({
  a: string(),
  b: number(),
  c: object(/* not sure what goes here */)
})