-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possibly null values in the input data? #20
Comments
I will check that after work. Some work needs to be done on Monolite to be adapted to last TypeScript features. |
ProxyThe problem comes from the fact that the accessor function takes as argument a Proxy created by Monolite, which is returned recursively to take all accessors from root. This means that This is a limitation of Monolite. It was just designed to enable static typing on the classic array of accessors used in Lodash or Immutable. Static OptimizationThis function is not meant to be really executed at runtime (it can but won't be compatible with older browsers, and will be less performing), and needs to be optimized statically. (See https://github.com/kube/babel-plugin-monolite) So here I would recommend to do Optional SubpropertyWhere we should stop in the object is something that should be determined by the library itself, maybe once we hit the first subproperty that is undefined, and then do nothing. (and return the same object without modification) This behaviour needs to be defined. I'm open to propositions. |
I see that you also did like the last comment in microsoft/TypeScript#16 (comment). ;) This Optional Chaining Operator is something I'm waiting for too. Monolite maybe needs to be reworked to be more compatible with upcoming features of JS and TypeScript. |
Ah, makes sense now that I understand how this library actually works :) The babel-plugin and the non-null-assertion operator probably is the most reasonable approach for now, but here's an idea:
EDIT: Misunderstood again. monolite already uses this approach. The exception I was seeing was coming from the setting phase not the path getting. But there is indeed a problem how the missing sub properties should be handled. I think ideally monolite should just create them like lodash.set does but how would mononite know how to create them? The itermediate objects might be Objects or Arrays. I don't think doing nothing would be a good idea because it will cause errors go unnoticed. It would be better to return a maybe type ( Yeah, the optional chaining operator is easily the most anticiated TS/JS feature for me. |
Maybe just create objects if the intermediate objects are missing and require usage of nested monolite calls when an array update is required? Like https://codesandbox.io/s/507z7665kl |
I just saw this new library https://github.com/facebookincubator/idx. |
I'm using
strictNullChecks
in my project. Updating an object with missing values will result in a runtime exception likeTypeError: Cannot read property 'bar' of undefined
.Here's an example. Am I doing something wrong here?
The text was updated successfully, but these errors were encountered: