canjs / can-observable-mixin

Define properties on JavaScript classes
https://canjs.com
MIT License
2 stars 1 forks source link

value behavior does not type-check nor convert resolved values #152

Open bmomberger-bitovi opened 4 years ago

bmomberger-bitovi commented 4 years ago

https://codepen.io/bmomberger-bitovi/pen/OJJGZZq

This should at very least warn in dev mode. Ideally it should have the same type checking as when the property is set externally.

phillipskevin commented 4 years ago

Type checking happens when the property is set, so errors are thrown if you set the prop instead of propValue.

bmomberger-bitovi commented 4 years ago

I don't see the two being mutually exclusive. We had the same discussion about type and default (when it was called value) ages ago, and I think that the principles still apply here.

phillipskevin commented 4 years ago

So you think we should type check twice? Type check when the value is set and type check when resolve is called?

bmomberger-bitovi commented 4 years ago

Yes, either twice, or only when resolve is called when a value behavior exists.

Alternatively we could pass type as a function parameter to the value behavior. But my gut instinct is that the flexibility to call the type checker/converter whenever isn't more beneficial than the simplicity of leaving it as declarative.