Switch to TypeScript? #766
Replies: 6 comments
-
I'd be interested in opportunistically trying out TypeScript on some smaller modules or code files, to get an impression of the benefits and drawbacks first-hand, before committing to making sweeping changes to the areas of the code I routinely work in. @okdistribute What do you think? |
Beta Was this translation helpful? Give feedback.
-
Yeah I would like to do this as well. While we're discussing types, I'd also like to consider rust :) there could be significant long-term benefits to this, and Hypercore has a pretty good first draft implementation. Tech-focused funders would jump at the opportunity -- I saw this with delta.chat, as they were able to raise $ with that consideration added. Practically and short-term, I think the benefits of typescript can be most beneficial for client state management components and high-level mapeo-core critical logic, such as sync. |
Beta Was this translation helpful? Give feedback.
-
While we're discussing types, I'd also like to consider rust :) there
could be significant long-term benefits to this, and Hypercore has a
pretty good first draft implementation. Tech-focused funders would
jump at the opportunity -- I saw this with delta.chat, as they were
able to raise $ with that consideration added.
A Rust rewrite could be fun, though I don't think performance is where
we're hurting the most right now on the backend. IMO correctness and
maintainability is the biggest pain-point. A super speedy (rusty?)
(webassembly-y?) frontend would be amazing though!
Practically and short-term, I think the benefits of typescript can be
most beneficial for client state components and high-level mapeo-core
critical logic, such as sync.
Agreed, especially re: sync. Materialized views might also benefit from
increased clarity & sanity checking, since they like to break on
unexpected inputs, which can brick a Mapeo install, since it'll keep
trying to re-index the same Message of Death.
|
Beta Was this translation helpful? Give feedback.
-
AFAICT, the main benefits for a rust rewrite are security and correctness guarantees. Performance would also be a benefit, of course. A webassembly frontend sounds challenging and likely heavy, since we'd also want to include React. The frontend might be more well suited for typescript |
Beta Was this translation helpful? Give feedback.
-
Hey, good discussion here, but maybe we should open a different issue somewhere to track this? I think I erroneously linked to this issue from our roadmap when discussing TypeScript, but this issue is specifically about switching Mapeo Mobile code, which is already typed with Flow, to being typed with TypeScript. I think starting to write backend code in TypeScript or porting to Rust could bring benefits (and costs!) and it would be useful to keep all that discussion somewhere. Would one of you like to open an RFC or an issue in mapeo-core about the TypeScript or Rust for mapeo/kappa-core discussion? |
Beta Was this translation helpful? Give feedback.
-
Yeah happy to! |
Beta Was this translation helpful? Give feedback.
-
We chose to use a a static type checker for Mapeo Mobile to reduce bugs in the code. It has been very helpful in many ways: we are passing around objects like Observations, Presets and Location status, which have a specific shape, and static type checking really reduces errors like "can't read property undefined". We chose flow as our static type checker because at the time (about 2 years ago) it had better React support than TypeScript and was "opt-in" - we could add it as we had time along the way.
Since then the React community seems to have switched to largely prefer TypeScript over Flow, and very few projects other than Facebook seem to use Flow. This is relevant because there are many up-to-date Typescript definitions for 3rd-party libraries that we use, which gives us increased coverage in our code and reduces bugs.
Overall using a static type checker has significant drawbacks too: I have found it can reduce productivity, especially when trying to work around limitations of the type checker, which results in wasted time reading StackOverflow figuring out how to correctly write the type for a particular function. It's a pain when doing initial prototyping, but in the same way as Test Driven Development, the time invested at the start can reduce problems further down the line.
Anyway, I'm opening this up to discuss whether we should switch from Flow to TypeScript. Not an immediate priority, but something to bear in mind. I think this article has a good overview of what is involved and the benefits/drawbacks:
Migrating a 50K SLOC Flow + React Native app to TypeScript
They took 3 engineers 10 days to migrate 50K SLOC. Mapeo Mobile is currently only 7.5K SLOC so it should be much less. It remains however a significant investment and only worth doing if it bring large payoffs.
Beta Was this translation helpful? Give feedback.
All reactions