gcanti / tcomb

Type checking and DDD for JavaScript
MIT License
1.89k stars 120 forks source link

add function support to defaultProps #311

Closed rkmax closed 6 years ago

rkmax commented 6 years ago

I'm using 3.2.24

I found this pretty useful for things like this

const Sample = t.struct({
  type: t.String,
  createdAt: t.Date
}, {
  defaultProps: {
    type: 'SAMPLE',
    createdAt: function() {
      return new Date();
    }
  }
});
gcanti commented 6 years ago

@rkmax what about a getter?

const Sample = t.struct({
  type: t.String,
  createdAt: t.Date
}, {
  defaultProps: {
    type: 'SAMPLE',
    get createdAt() {
      return new Date();
    }
  }
});
rkmax commented 6 years ago

@gcanti thank you that works, I feel dumb :man_facepalming: overthinking it