Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using more than one custom type on the same object fails #5

Closed
trodrigues opened this issue Feb 26, 2016 · 0 comments
Closed

Using more than one custom type on the same object fails #5

trodrigues opened this issue Feb 26, 2016 · 0 comments

Comments

@trodrigues
Copy link

Hi there,

I was trying to create a type definition where I'd have two custom types being used on two separate properties of an object.

Essentially, something like: '{prop1: CustomType1, prop2: CustomType2}'

However, this seems to fail in a very weird way if my custom type reuses type-check itself to validate something.

But it doesn't fail if there is only one custom type being used. I created 2 isolated test cases to demonstrate. The first one doesn't fail, but the second one does. Also, the inner assert inside the validation method is passing, so the inner use of typeCheck is working properly.

var typeCheck = require('type-check').typeCheck
var assert = require('assert')

// asserts to true
assert(typeCheck('{prop1: CustomType1, prop2: String}', {
  prop1: {
    subprop1: 'str1'
  },
  prop2: 'str2'
}, {
  customTypes: {
    CustomType1: {
      typeOf: 'Object',
      validate: function (x) {
        var firstcheck = typeCheck('String', x.subprop1)
        assert(firstcheck, 'first check')
        return firstcheck
      }
    }
  }
}))

// asserts to false
assert(typeCheck('{prop1: CustomType1, prop2: CustomType2}', {
  prop1: {
    subprop1: 'str1'
  },
  prop2: {
    subprop2: 'str2'
  }
}, {
  customTypes: {
    CustomType1: {
      typeOf: 'Object',
      validate: function (x) {
        var firstcheck = typeCheck('String', x.subprop1)
        assert(firstcheck, 'first check')
        return firstcheck
      }
    },
    CustomType2: {
      typeOf: 'Object',
      validate: function (x) {
        var secondcheck = typeCheck('String', x.subprop2)
        assert(secondcheck, 'second check')
        return secondcheck
      }
    }
  }
}))

I tried debugging this and stepping into the code of the library but couldn't really figure out where and why it fails.

@gkz gkz closed this as completed in b518bbc Apr 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant