3 ms·
Also did something similar[1]. My motivations were a better API (mine is modeled off of Elm's), and better error messages: I have a use case where user's need t
by nateabele 7y ago
Also did something similar[1]. My motivations were a better API (mine is modeled off of Elm's), and better error messages: I have a use case where user's need to be shown raw, dev-tools-style interactive data dumps, with error information overlaid on top. The next version will also enable data generation from schemas.
Also, and perhaps most importantly, this library has no respect for undefined, because particularly in the context of data modeling, undefined is complete nonsense.
[1] https://github.com/ai-labs-team/ts-utils#decoder https://github.com/ai-labs-team/ts-utils#decoder
- Gehinnn 7y agoI find `undefined` better than `null`. Either a user has contact information, or the contact information are undefined (and not null). How do you model that?
- nateabele 7y agoSee, I take the opposite view: consider that the 'model' is the abstract structure of the data which your application knows about. In your case, contact info is a piece of related data that your application knows about, can traverse to, parse, and consume, and it can be either present or absent. To me, `null` fits that case perfectly (personally I'd use Maybe, but, same idea). Finally, in cases where you're modeling a collection of values where the keys are unknown, see `dict()`.
- Gehinnn 7y agoWhat is `dict()`? What's the meaning of `null`? `undefined` literally means the value is not defined. `null` only has a technical meaning, which says its value is the null pointer.
- Dylan16807 7y agoThat's not what null means in javascript and typescript. There, it's more like 'null' signals that there is no value, and 'undefined' signals that there is no variable.
- Gehinnn 7y agoAll runtime differences are quite neglectable if you use typescript, at least in my experience. You never accidentally use unassigned variables in typescript. Also, `{ x: undefined }` and `{}` are distinguishable. Undefined plays well together with optional fields in typescript, null does not and requries normalization! `undefined` in a JSON array is a problem though.