Skip to content

Commit

Permalink
Merge pull request #141 from canjs/fix-array-weirdness-in-error-message
Browse files Browse the repository at this point in the history
Error message improvment for arrays
  • Loading branch information
cherifGsoul authored Oct 15, 2019
2 parents 95dc2a7 + 7b7a771 commit 138dc81
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/define.js
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ getDefinitionOrMethod = function(prop, value, defaultDefinition, typePrototype){
definition = { default: value, type: Function };
}
} else if( Array.isArray(value) ) {
definition = { type: value };
definition = { type: type.normalize(Array) };
} else if( canReflect.isPlainObject(value) ){
definition = value;
}
Expand Down
18 changes: 18 additions & 0 deletions test/define-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,21 @@ dev.devOnlyTest('On error include the name of the property that is being set', f
assert.equal(error.message, '4 is not of type Number. Property age is using "type: Number". Use "age: type.convert(Number)" to automatically convert values to Numbers when setting the "age" property.');
}
});


dev.devOnlyTest('Handle types as arrays to fix "Right-hand side of instanceof is not callable for arrays"', function(assert) {
class Foo extends mixinObject() {
static get props() {
return {
list: []
};
}
}
var foo = new Foo();
foo.list = [ "one", "two" ];
try {
assert.ok(true, 'No errors, it handles arrays values as type');
} catch (error) {
assert.ok(error.message);
}
});

0 comments on commit 138dc81

Please sign in to comment.