canjs / can-observable-mixin

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

Cannot default property to null / undefined without setting type #148

Closed m-mujica closed 4 years ago

m-mujica commented 5 years ago

Defining an element like this:

class MyElement extends StacheElement {
  static get view() {
    return "<p>hello</p>";
  }

  static get props() {
    return {
      thisIsNull: { default: null },
      thisIsUndefined: { default: undefined }
    };
  }
}

causes the following line to throw an error https://github.com/canjs/can-observable-mixin/blob/fa5a085a9bed861175adc63f5dc7d230b584807c/src/define.js#L880.

A workaround is to add a type like thisIsNull: { default: null, type: type.maybe(String) }.

What should can-observable-mixin set type to if the default value is null / undefined?

phillipskevin commented 4 years ago

I think we should just prevent this error so that it is basically a type.Any.