mobx-state-tree
mobx-state-tree copied to clipboard
if ("get" in descriptor) is blocking from using 'target' as an attribute in my model
I have:
- [x] A conceptual question.
- [x] I've checked documentation and searched for existing issues
- [ ] I tried GitHub Discussions first
- [x] I think something is working as it was coded.
- [x] But I also think it introduced a regretful side-effect
- [ ] I think something is not working as it should.
- [ ] I've checked documentation and searched for existing issues
- [ ] I've made sure your project is based on the latest MST version
- [ ] Fork this code sandbox or another minimal reproduction.
- [ ] Describe expected behavior
- [ ] Describe observed behavior
- [ ] Feature request
- [ ] Describe the feature and why you feel your feature needs to be generically solved inside MST
- [x] Are you willing to (attempt) a PR?
Not following the above template might result in your issue being closed without further notice
I upgraded MST from v3.17.2 to v5.0.1 (I know a pretty big step) I also introduced Typescript into my project.
I'm fairly new to TS so I was assuming I was doing something wrong. after a day or so of digging I came across this lovely bit of code in file mobx-state-tree/packages/mobx-state-tree/src/types/complex-types/model.ts
// the user intended to use a view
const descriptor = Object.getOwnPropertyDescriptor(props, key)!
if ("get" in descriptor) {
throw fail("Getters are not supported as properties. Please use views instead")
}
The problem is that I was trying to use an attribute named target :-|
Do you se the problem? ;-)
Maybe we could change the above to (or something similar)
// the user intended to use a view
const descriptor = Object.getOwnPropertyDescriptor(props, key)!
if (descriptor.match(/^get /i)) {
throw fail("Getters are not supported as properties. Please use views instead")
}
I know descriptor is not a string ;-) but you get the idea.