G
Giulio Canti
gcanti.github.io · Personal blog · on HN since 2014
Giulio Canti writes about typed functional programming in TypeScript and is the author of fp-ts, io-ts and tcomb.
What HN saysHN commenters link it as the home of fp-ts, called the strictest functional implementation in TypeScript, and one uses its Either type happily.
33HN people shared it
28linked it in comments
19stories submitted
85story points
12 months agolast shared
2014people per year2026
Most-shared posts
- 1Typed Functional Programming in TypeScript10 people · 3 points · first shared 2019 · discussion on HN
- 2Io ts6 people · first shared 2020
- 3Understanding React and reimplementing it from scratch3 people · 8 points · first shared 2014 · discussion on HN
- 4Show HN: Tcomb.js – JavaScript types and combinators3 people · 2 points · first shared 2014 · discussion on HN
- 5Modules3 people · first shared 2019
- 6Function.ts3 people · first shared 2022
- 7Replacing propTypes with type annotations in React 0.132 people · 3 points · first shared 2015 · discussion on HN
- 8Show HN: A playground for react-bootstrap with debugging support2 people · 2 points · first shared 2014 · discussion on HN
- 9Either.ts2 people · first shared 2022
- 10What if your domain model could validate the UI for free?1 people · 27 points · first shared 2014 · 7 comments on HN
- 11Six reasons to define JavaScript constructors with only one argument1 people · 11 points · first shared 2014 · discussion on HN
- 12Show HN: Tcomb-form – React.js UI library for developing forms writing less code1 people · 7 points · first shared 2014 · 1 comments on HN
- 13JSON Api deserialization into an object model with tcomb.js1 people · 6 points · first shared 2014 · discussion on HN
- 14An alternative syntax for React propTypes1 people · 5 points · first shared 2014 · discussion on HN
- 15Introduction to set theory with JavaScript1 people · 5 points · first shared 2014 · discussion on HN
What HN people wrote when they linked it
epolanski · 2025-11-18
fp-ts is the strictest fp implementation in typescript land.
https://gcanti.github.io/fp-ts/modules/
But the most popular functional ecosystem is effect-ts, but it does it's best to _hide_ the functional part, in the same spirit of ZIO.
https://effect.website/
rekoros · 2024-04-21
I think it’s great that functional programming is making its way into traditional imperative languages - even JavaScript (I recently came across https://gcanti.github.io/fp-ts/ as a pretty extreme example)
Elixir/Erlang has function-level pattern matching, which I really like. I’ve yet to see it anywhere else, though my understanding is it came from Prolog.
satvikpendem · 2023-01-24
I use fp-ts with its Either type (like Result in other languages like Rust), works great.
https://gcanti.github.io/fp-ts/
Ideabile · 2022-08-07
This is great, thanks for sharing.
I'm currently using @arrows/composition https://caderek.github.io/arrows/packages/composition/#pipe because of the light way library approach, which you seem to share.
I also try fp-ts https://github.com/gcanti/fp-ts but is a bit an academic style, so difficult to introduce in everyday work. Implementation of pipe: https://gcanti.github.io/fp-ts/modules/function.ts.html#pipe
I still need to wrap my head on your use of generics, but yours looks more flexible than the static type approach that other libraries (include RxJS) implements, does your pipe support types for any length of arguments? Does require a specific version of TypeScript?
Nice work.
belmont_sup · 2023-01-16
I forgot where I read this, but I'll paraphrase: it's easier to work with 10 objects with 1000 applicable functions than with 1000 objects with 10 methods each.
In Haskell or other typed fp languages, you have all these well-recognized and well-used typeclasses and their attached methods, conceptually equivalent to generic interfaces in c#/java. It's easier to adapt new data structures into these interfaces and have all your existing functions immediately work with them.
The "mathematics" part here is that these typeclasses are backed by category theory that prescribes their behaviors.
There are plenty of random readings you can find, so I won't recommend them. Someone's bound to argue with me on what's a better entrypoint.
I do want to note that you don't need to use haskell or an fp language to use these concepts. Example: a complete set of fp data structures in typescript https://gcanti.github.io/fp-ts/modules/. It's just that fp languages make using them much easier because of their type system.
dakom · 2019-06-19
Several comments here are along the lines of "I haven't done much monadic error handling but here's why it's bad."
That's silly because the benefits of this type of programming can't be grokked until you use it on real projects.. it's honest-to-goodness not enough to look at small examples and judge whether it's worthwhile or not.
There's a lot of this realization going around actually - for example Rust's main raison d'être is basically: "look - we _can_ write safe c/c++, some of us can even nail it perfect every time in small examples, but in large apps it's inevitable that we'll all make mistakes"
Here's two issues with try/catch in real-world apps:
1. You aren't forced to write it. It's simply possible to forget that a function might fail (e.g. when that failure is defined as a side-effect). This is even worse when there's no type system forcing you to think about it. We all make this mistake!
2. You can't easily distinguish between expected errors and unexpected errors - and even where you can, dealing with that becomes a big mess.
Unexpected errors (like "out of memory", "computer is quitting", "electricity is gone") - _should_ crash and burn and stop the app (unless you explicitly have a way to recover from it - in which case it's actually an _expected_ error). Letting the app continue on where there's undefined behavior is dangerous.
Expected errors (like "user not found", "wrong password", perhaps even "network down") need to be dealt with. Every single time.…
wk_end · 2025-07-04
Assuming you've got experience with Javascript, read the "Motivation" section on the monocle-ts website:
https://gcanti.github.io/monocle-ts/
vmfunction · 2024-08-14
> I do wish that Typescript would offer some tools to make it more ergonomic to write performant unifying code (I kind of despise conditional types
Maybe give https://gcanti.github.io/fp-ts/ a go?
maxbond · 2024-05-20
You might be interested in `fp-ts` (and the related `io-ts`).
https://gcanti.github.io/fp-ts/
https://gcanti.github.io/io-ts/
quaunaut · 2024-03-24
While I certainly agree, I've found that this is often an indication of too-complex an architecture, and a fundamental re-think being necessary. I've had projects that depend on [fp-ts], which end up incredibly generic-heavy, but still make it entirely through a typecheck(not build- typescript's just worse at that than other tools like esbuild) in seconds-at-worse.
Obviously depends on your organization/project/application, but I do like these things as complexity-smells.
[fp-ts]: https://gcanti.github.io/fp-ts/
toastal · 2023-08-17
fp-ts has this same unfortunate issue (https://gcanti.github.io/fp-ts/guides/purescript.html#data) where a PureScript one-liner becomes 11 lines of boilerplate TypeScript. Or (https://gcanti.github.io/fp-ts/guides/purescript.html#pattern-matching… 3 lines of pattern matching becomes 10 where the matching is done on strings (ad-hoc _tag property).
programmarchy · 2023-05-06
I’ve been using io-ts for this and been very happy with it. [1] It’s similar to Swift’s Coding protocol in case you’re familiar.
[1] https://gcanti.github.io/io-ts/
creakingstairs · 2023-05-04
looks like more ergonomic/focused version of fp-ts[1] Thanks for sharing!
[1] https://gcanti.github.io/fp-ts/
halfmatthalfcat · 2023-03-16
fp-ts (and most functional libraries) have a handy Either type just for this: https://gcanti.github.io/fp-ts/modules/Either.ts.html
gherkinnn · 2022-09-20
fp-ts [0] and the accompanying io-ts [1] are very well designed and neatly implemented. I'd consider them the reference for all things FP in Typescript.
In practice though I find that they don't mesh well with the language and ecosystem at large. Using them in a React/Vue/Whatever app will catch you at every step, as neither the language nor the frameworks have these principles at their core. It takes a lot of effort to escape from their gravitational pull. Using Zod [2] for your parsing needs and strict TS settings for the rest feel more natural.
It could work in a framework-agnostic backend or logic-heavy codebase where the majority of the devs are in to FP and really want / have to use Typescript.
0 - https://gcanti.github.io/fp-ts/
1 - https://gcanti.github.io/io-ts/
2 - https://zod.dev
harg · 2022-08-08
I agree. This is what fp-ts's pipe[1] function does. It also has flow[2], which is basically a reversed compose.
[1]: https://gcanti.github.io/fp-ts/modules/function.ts.html#pipe
[2]: https://gcanti.github.io/fp-ts/modules/function.ts.html#flow
wlamartin · 2022-02-11
Sure, there's many ways to skin a cat. Given the option, I wouldn't choose either of these, and instead use something like filterMap[1] which I think conveys intent better than a fold or flatMap.
Btw, I'm assuming that the original map questioner wasn't solely using flatMap for side-effectful iteration, which reading again, I'm a bit suspicious about.
1: https://gcanti.github.io/fp-ts/modules/Array.ts.html#filtermap
wereHamster · 2021-12-31
My point is that you can't override what equality implementation groupByToMap will use, which makes it much less useful.
See for example https://gcanti.github.io/fp-ts/modules/NonEmptyArray.ts.html#group, where you can supply your own equality function…
move-on-by · 2021-09-10
I've never seen runtypes, but I've seen io-ts [1]. Are you aware of the pros/cons between them?
[1] https://gcanti.github.io/io-ts/
lhnz · 2021-05-15
It doesn't use json schema but you might be interested in something like this: https://gcanti.github.io/io-ts/
(You can define runtime encoder/decoders which produce typed values.)
shirogane86x · 2021-05-10
As far as i remember there's functions that take explicit typeclass dictionaries (that you can compose via contramap). So I guess they sort of do typeclasses, but without implicits, which is pretty painful IME. Example: https://gcanti.github.io/fp-ts/modules/Functor.ts.html#map
100ideas · 2020-02-18
You might find io-ts useful [1].
“io-ts introduces the concept of a runtime type (an instance of the Type class) which represents a runtime validator for a typescript (static) type. [2]”
See:
[1] https://gcanti.github.io/io-ts/
[2] https://lorefnon.tech/u2018/03/25/typescript-and-validations-at-runtim…
natrius · 2016-02-07
The Python community just doesn't have good tools to type dictionaries. In JavaScript, you can use a tool like tcomb[1] that lets you specify the structure of your data and add functionality onto that data. Throwing raw dictionaries around in your program isn't maintainable, but if you adopt the Clojure ethos that functions operate on data that meets a set of requirements, you'll have maintainable code without a type system that gets in your way when you don't need it.
In general, I think most Python developers would be happier with Clojure or JavaScript written in a functional style (e.g. heavy use of tcomb, Immutable.js, and transducers). I'm happier, at least.
[1] https://gcanti.github.io/tcomb/
zzzaim · 2015-04-27
Interesting take on runtime type checking. Have you seen tcomb (http://gcanti.github.io/tcomb/)? I've been using it myself and I like this idea of using it for domain driven design. Check it out if you haven't, maybe you can find something to differentiate as avocado is still in its early stages.
gcanti · 2014-10-29
> One reason for this change is to make it possible to use object literals or record syntax where that is more appropriate than function calls
I think this will be the most revolutionary aspect in the next months, both for development and tests. I wrote an article explaining why I have this opinion:
https://gcanti.github.io/2014/10/29/understanding-react-and-reimplemen…
BinaryBullet · 2014-09-04
This looks pretty cool:
http://gcanti.github.io/resources/tcomb-react-bootstrap/playground/pla…
arnejenssen · 2023-06-09
I'm using fp-ts https://gcanti.github.io/fp-ts/
mebassett · 2023-04-09
I have used elm for a smallish (10 people or so?) team writing software for revenue, and regretted it. that was 4-5 years ago. my reasons had a lot to do with the community around elm, which other comments allude to. This group had different concerns to mine:
The thing that ultimately tipped the balance in React’s favour for us was that we acquired another company whose entire codebase was written in React, and whose team knew nothing about Elm. Overnight, we went from a company that was writing about equal amounts of Elm and React (and which might well have decided to double down on Elm) to one that was writing about 75% React.
By that time, TypeScript had grown to be capable enough (and developer-friendly enough) to balance much of what sold us on Elm originally: a usable type system, good-enough error messages, etc. React had baked in some more useful state management primitives that roughly matched Elm’s “batteries included” state management.
if you like the ideas in elm but don't want to commit to it I'd encourage you to check out elm-ts (https://gcanti.github.io/elm-ts/). It has a little bit more boilerplate than elm (I find elm to be quite verbose already!) but a better experience for individuals and teams overall, I would say. It's a good example of how "TypeScript had grown to be capable enough (and developer-friendly enough) to balance much of what sold us on Elm originally: a usable type system.."