You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.
Should not error on intersection type as property of struct.
Actual behaviour
Invalid value error.
/Users/chris/Projects/testtest/node_modules/tcomb/lib/fail.js:2
throw new TypeError('[tcomb] ' + message);
^
TypeError: [tcomb] Invalid value {
"string": "Test"
} supplied to Struct{a: Struct{string: {String | <function1>}} & Struct{string: {String | <function1>}}}/a: Struct{string: {String | <function1>}} & Struct{string: {String | <function1>}}
at Function.fail (/Users/chris/Projects/testtest/node_modules/tcomb/lib/fail.js:2:9)
at assert (/Users/chris/Projects/testtest/node_modules/tcomb/lib/assert.js:14:12)
at Intersection (/Users/chris/Projects/testtest/node_modules/tcomb/lib/intersection.js:27:7)
at create (/Users/chris/Projects/testtest/node_modules/tcomb/lib/create.js:10:66)
at new Struct (/Users/chris/Projects/testtest/node_modules/tcomb/lib/struct.js:82:19)
at Object.validateStruct [as struct] (/Users/chris/Projects/testtest/node_modules/tcomb-validation/index.js:173:17)
at recurse (/Users/chris/Projects/testtest/node_modules/tcomb-validation/index.js:71:38)
at Function.validate (/Users/chris/Projects/testtest/node_modules/tcomb-validation/index.js:66:31)
at Object.<anonymous> (/Users/chris/Projects/testtest/run.js:28:18)
at Module._compile (module.js:413:34)
Steps to reproduce
Run the following code (note how the alternative commented lines work fine):
constt=require('tcomb-validation');constMin=t.refinement(t.String,(s)=>s.length>2);constMax=t.refinement(t.String,(s)=>s.length<5);constTypeA=t.struct({string: Min});constTypeB=t.struct({string: Max});constType=t.struct({test: t.intersection([TypeA,TypeB])});constval={test: {string: 'Test'}};//const Type = t.intersection([TypeA, TypeB]);//const val = {string: 'Test'};constresult=t.validate(val,Type);console.log(result);
Stack trace and console log
Will follow up with this if required!
Thanks in advance! :)
Ps. Sorry if this is wrong repo, my guess was this is more core tcomb rather than actually validation related
The text was updated successfully, but these errors were encountered:
thanks for the detailed report. This is an edge case: please note how, since structs are nominal (i.e. their is functions are implemented with instanceof) this set is empty:
t.intersection([TypeA,TypeB])
so, from a theoretical point of view, the current behavior is correct.
Version
3.2.3
Expected behaviour
Should not error on intersection type as property of struct.
Actual behaviour
Invalid value error.
Steps to reproduce
Run the following code (note how the alternative commented lines work fine):
Stack trace and console log
Will follow up with this if required!
Thanks in advance! :)
Ps. Sorry if this is wrong repo, my guess was this is more core
tcomb
rather than actually validation relatedThe text was updated successfully, but these errors were encountered: