gcanti / tcomb-validation

Validation library based on type combinators
MIT License
400 stars 23 forks source link

Dict example from README not working #25

Closed ivan-kleshnin closed 9 years ago

ivan-kleshnin commented 9 years ago

First, pls look at this:

An error in documentation?!

var Country = t.enums.of('IT, US', 'Country'); // 'IT, US' should be "IT", "US" ???

Second:

import tc from "tcomb";
import {validate} from "tcomb-validation";

// a dictionary of numbers
let Country = tc.enums.of("IT", "US", "Country");
let Warranty = tc.dict(Country, tc.Number);

console.log(validate({US: 2, IT: 1}, Warranty).isValid()); // => false instead of true

Error message:

{ message: 'Invalid value "IT" supplied to /IT: Country',
  actual: 'IT',
  expected: 
   { [Function: Enums]
     meta: { kind: 'enums', map: [Object], name: 'Country' },
     displayName: 'Country',
     is: [Function] },
  path: [ 'IT' ] }
gcanti commented 9 years ago

Ops, a typo, should be

let Country = tc.enums.of(["IT", "US"], "Country");

Thanks for pointing out!

ivan-kleshnin commented 9 years ago

Thank you!