This is a great article, thanks for sharing your thoughts. When switching to TypeScript this is one of the first things I thought: should I create a Maybe implementation right at the very beginning of the transition? I think I will stick with Nullable as this is already represented in TS, but I am still curious of how things can escalate badly when implementing the Maybe in a TS project.
I also like the idea of a chainNullable in order to compose. The "if not null" check still bothers me a little :)
I am Software Developer, currently interested in static type languages (TypeScript, Elm, ReScript) mostly in the frontend land, but working actively in Python also. I am available for mentoring.
Hey Lucas, tnx for comment. So you can implement Maybe, use it, nothing bad will happen outside of the fact that null will not disappear, and you need to watch out your back, because in any third party lib, the null is still some kind of standard, not surprisingly though. What does it mean is that you will need to protect your project from using any null things, including newest staff like nullish coalescing operator and optional chaining, also you will need to replace standard JS API like Array into some wrapper, as standard Array uses null | undefined. Another subject is communication with server, JSON will send you null fields, those need to be parsed and changed to Maybe, allowing any null to go through your code means that finally you have Nothing | null | undefined as extra-nullish :D.
So to sum it up, you can, but it demands a lot of project rules, and avoiding part of the language syntax and part of the language build interfaces. There is no really going back from that I would say.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This is a great article, thanks for sharing your thoughts. When switching to TypeScript this is one of the first things I thought: should I create a Maybe implementation right at the very beginning of the transition? I think I will stick with Nullable as this is already represented in TS, but I am still curious of how things can escalate badly when implementing the Maybe in a TS project.
I also like the idea of a
chainNullable
in order to compose. The "if not null" check still bothers me a little :)Hey Lucas, tnx for comment. So you can implement Maybe, use it, nothing bad will happen outside of the fact that null will not disappear, and you need to watch out your back, because in any third party lib, the null is still some kind of standard, not surprisingly though. What does it mean is that you will need to protect your project from using any null things, including newest staff like nullish coalescing operator and optional chaining, also you will need to replace standard JS API like Array into some wrapper, as standard Array uses null | undefined. Another subject is communication with server, JSON will send you null fields, those need to be parsed and changed to Maybe, allowing any null to go through your code means that finally you have
Nothing | null | undefined
as extra-nullish :D.So to sum it up, you can, but it demands a lot of project rules, and avoiding part of the language syntax and part of the language build interfaces. There is no really going back from that I would say.