-
Notifications
You must be signed in to change notification settings - Fork 120
Declare assertion issue #291
Comments
the type given to Type2.define(Type1.extend(Children)); |
@gcanti Thanks for the reply, I can live with that .. but I can't define any functions in the prototype either .. is there a way to get around that? I tried defining it before the |
Can't repro const Type1 = t.struct({
foo: t.String
});
const Type2 = t.declare('Type2');
const Children = t.struct({
children: t.maybe(t.list(Type2))
}, 'TypeChildren');
Type2.define(Type1.extend(Children));
Type2.prototype.getFoo = function () {
return this.foo
};
Type2.prototype.getChildrenLength = function () {
return (this.children || []).length
};
const x = Type2({ foo: 'bar', children: [{ foo: 'baz' }] })
console.log(x.getFoo()) // => bar
console.log(x.getChildrenLength()) // => 1 |
I believe I made a mistake when I said defining a function on Updated the issue. Also @gcanti is there a specific reason for these assertions? This improves readability when throwing errors. It would read |
IIRC those assertions were added to try to prevent using non-throwaway types |
Like what I have right now? Seems like intentional limitation. Can you consider this a bug and allow removing it? At least the second assertion? |
No, you are actually providing a fresh type ( |
Thanks! Removing that limitation will be helpful, unless this is needed for something else, in that case, the only solution I have right now is not to extend but duplicate the |
Just released a patch |
version: 3.2.1
line in question:
tcomb/lib/declare.js
Line 34 in 5bbaf1a
So can someone please explain why this is throwing error, and how the assertion works? Why would it assert the name to be null and not to have a prototype? and then reassign the same here:
tcomb/lib/declare.js
Line 47 in 5bbaf1a
My code:
I am getting error from the above mentioned line, because I have a name provided. Also the error doesn't exactly explain whats wrong! it is saying "define a fresh type" .. I even tried a singleton module (before code reading) but getting the same error.
Please help.
Update: The assertion is failing if
Type1
has a function defined on prototype notType2
The text was updated successfully, but these errors were encountered: