canjs / can-observable-mixin

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

Better error message when definitions.value is not a function #146

Closed m-mujica closed 4 years ago

m-mujica commented 4 years ago
static get props() {
  return {
    first: { type: String, value: "Kevin" },
    last: { type: String, value: "McCallister" },
    get name() {
       return this.first + " " + this.last;
    }
}

I used value like ^ (muscle memory I guess) and I got the following error:

TypeError: Object.defineProperty called on non-object
    at Function.defineProperty (<anonymous>)
    at Function.define.property (http://127.0.0.1:5500/node_modules/can-observable-mixin/src/define.js:310:11)
    at Object.eval (http://127.0.0.1:5500/node_modules/can-observable-mixin/src/define.js:140:10)
    at String.eval (http://127.0.0.1:5500/node_modules/can-reflect/reflections/shape/shape.js:517:21)
    at Object.eachListLike (http://127.0.0.1:5500/node_modules/can-reflect/reflections/shape/shape.js:448:17)

Here: https://github.com/canjs/can-observable-mixin/blob/master/src/define.js#L305-L310

Which is really confusing, we should probably error if value is not a function.