Migrating 300k LOC from Flow to TypeScript
1–10 of 87 posts
Re: Migrating 300k LOC from Flow to TypeScript
#2(Closure is a venerable JavaScript type system by Google using JSDoc-like annotations.)
Stop the world migration, automated scripts, manual fixes, lots of ts-ignore/any. And thoroughly worth it.
[1] https://www.lucidchart.com/techblog/2017/11/16/converting-60...
Re: Migrating 300k LOC from Flow to TypeScript
#31. Both TypeScript and Flow are gradual type systems. They both explicitly allow escaping the safety and coverage of a type system, either to allow easier interop with existing JavaScript packages or to allow existing JavaScript codebases to incrementally adopt types. So there are always holes in which errors are reported, regardless of whether they had to silence some explicitly or not. By measuring the extent, they have a yardstick against which they can drive further type adoption.
2. Repeatability is the only way to do large code migrations. Write the steps in a script, run it, find the bugs in the script, fix the script, and repeat. With 300k lines of code no doubt they have dozens or hundreds of people committing daily. So a script is the only way to sneak in during off-hours, get something in that doesn’t race to conflict with someone else, and land the change. A long running, manually crafter branch here would not work—it would effectively operate as a fork of the codebase for the entire duration of the migration, with all the downsides that a fork entails.
Kudos to the team; this is a very impressive feat!
Re: Migrating 300k LOC from Flow to TypeScript
#4Similar decisions to what we made at Lucidchart 2 years ago for migrating 600 KLOC of Closure to TypeScript. [1] (Closure is a venerable JavaScript type system by Google using JSDoc-like annotations.) Stop the world migration, automated scripts, manual fixes, lots of ts-ignore/any. And thoroughly worth it. [1] https://www.lucidchart.com/techblog/2017/11/16/converting-60...
Re: Migrating 300k LOC from Flow to TypeScript
#5Similar decisions to what we made at Lucidchart 2 years ago for migrating 600 KLOC of Closure to TypeScript. [1] (Closure is a venerable JavaScript type system by Google using JSDoc-like annotations.) Stop the world migration, automated scripts, manual fixes, lots of ts-ignore/any. And thoroughly worth it. [1] https://www.lucidchart.com/techblog/2017/11/16/converting-60...
How do you feel about Typescript 2 years after switching? Anything that you wished you known before, that you've had to learn on the way?
TypeScript just keep getting better and better. I am looking forward to better Google Bazel support for TypeScript to help with monorepos.
Re: Migrating 300k LOC from Flow to TypeScript
#6https://www.typescriptlang.org/docs/handbook/advanced-types....
Intersection Types - An intersection type combines multiple types into one.
Union Types - A union type describes a value that can be one of several types
Type Guards - A type guard is some expression that performs a runtime check that guarantees the type in some scope.
Nullable types - compiler level safety for "can be a null " implication of any type
Type alias - as the name suggests
String literal types - Union type of few string values
Numeric literal types - Union type of few numeric values
Enum Member Types - enum members have types when every member is literal-initialized
Discriminated Unions - You can combine singleton types, union types, type guards, and type aliases
Index Types - you can get the compiler to check code that uses dynamic property names
Mapped Types - Transforms each property in the old type in the same way to create new type.
Conditional Types - selects one of two possible types based on a condition expressed as a type relationship test
Re: Migrating 300k LOC from Flow to TypeScript
#7My impressions are mostly positive in the sense that if you are doing JS, you are better off doing TS. The tooling is great and you can start with simple changes that almost immediately start giving clear benefits in terms of typing related warnings and other improvements. Typescript is minimally intrusive in the sense that all js is valid ts and you can gradually improve it by adding type annotations and addressing warnings.
The benefits are a vastly improved safety net at a very minimal cost, smarter tools, and more confidence that a given piece of code will not break with some entirely preventable error (like an NPE). Excluding whole categories of bugs is a good thing. For new code, I consider it a no brainer. Most new projects seem to default to using typescript so I guess more people have come to the same conclusion. Lots of upsides, no real downsides that I know off. You'd have to be pretty stubborn to opt out at this point. For older code that you still care about, migrating is a good investment as well: you will improve the code. Any other code you probably need to get rid off anyway.
That being said, I believe typescript is merely a gateway drug. Typescript is great and you definitely should use the strict mode. But even in the strict mode it still inherits a lot of cruft from javascript and this makes life needlessly hard. Other languages don't have this problem and the progression from the js/ts ecosystem to other things is very obvious with some younger full stack engineers I've known for a few years. Go and Rust seem particularly popular lately. And even Kotlin seems to be well liked (big fan myself).
Better still, a lot of these languages are coming to the browser (via WASM or transpilation). Inevitably, some projects will start moving away from defaulting to the js/ts ecosystem for frontend work. Right now you'd be a very early adopter but things are improving rapidly and there are some early adopters. I played a bit with kotlin-js recently and while it still has lots of rough edges, it actually works quite well. Not quite a drop-in replacement for typescript just yet but most of that is related to consuming javascript from kotlin; which I'd argue is short term needed but long term undesirable and likely to become less important as native kotlin frameworks emerge (e.g. kvision is a popular one). Tip, parcel recently added kotlin support; works without extra configuration even.
Re: Migrating 300k LOC from Flow to TypeScript
#8I recently spent some time introducing typescript to a javascript code base. My background is mostly backend/JVM, so I wasn't the perfect person to be doing this obviously. But as there was nobody else and I needed to own this stuff, I put in the work and got things done. My impressions are mostly positive in the sense that if you are doing JS, you are better off doing TS. The tooling is great and you can start with…
> Better still, a lot of these languages are coming to the browser (via WASM or transpilation)
I think this has always been a concern - CoffeeScript had its moment in the sun, then the good parts got merged into JS and it died out. We'll see if that happens again.
WASM concerns me, though, because of the utility you outline, which doesn't actually serve the end-user in any way shape, or form. Much like we're seeing tiny webapps made with React (and requiring browsers to download and parse the accompanying runtime), I worry we're going to see sites using e.g. Kotlin in WASM simply because that's the developer preference, totally ignoring the fact that it means every user is going to have to download a Kotlin runtime and garbage collector despite there being a perfectly good JavaScript one sitting right there.
Re: Migrating 300k LOC from Flow to TypeScript
#9TypeScript is a hack of epic proportions and every so often the reality rears its ugly head in the form of failed source mapping, version compatibility issues, unexpected types during runtime, poor architectural decisions aimed at pleasing the compiler instead of fulfilling project goals.
TypeScript is a very poor way to model real-world systems because it incorrectly assumes that real-world entities have a fixed type schema. This is obviously wrong. Real-world objects change over time and most things cannot be categorised clearly. A tadpole turns into a frog and learns the ability to walk. Some people are disabled and cannot walk. Some cars have 6 wheels. There is no fixed type schema for anything in the real world; it is filled with anomalies so why should we design systems to model such unrealistic objects? Why not force the developers to account for as many cases and schemas as possible, it's our job!
Re: Migrating 300k LOC from Flow to TypeScript
#10I recently spent some time introducing typescript to a javascript code base. My background is mostly backend/JVM, so I wasn't the perfect person to be doing this obviously. But as there was nobody else and I needed to own this stuff, I put in the work and got things done. My impressions are mostly positive in the sense that if you are doing JS, you are better off doing TS. The tooling is great and you can start with…
I absolutely agree on TypeScript, I love that it's opinionated and simply versioned. Every time I have to step back into a codebase that uses Babel and X number of different plugins it just tires me. Typescript is just Typescript, and the compiler works fantastically well. > Better still, a lot of these languages are coming to the browser (via WASM or transpilation) I think this has always been a concern - CoffeeScri…
WASM is currently indeed bottlenecked on the lack of GC. This is being worked on. I expect a lot of progress over the next two years that will gradually remove most of the obstacles on this and other fronts. None of these are fundamental issues; it's just a matter of things not being perfect yet. Despite this, there's already a lot of early adoption. But I agree that Kotlin on WASM is short term not ideal. In the same way C#/Blazor currently only makes sense for enterprise application where download size is less of a concern. Rust does not really need GC, which is why is a popular language for this already.
As far as bloat is concerned; react is actually pretty horrible. I've seen simple react applications go over 1 MB for no good reason. I'd say the react ecosystem is actually a main driver for people wanting to have some alternatives. I actually prefer more lean approaches. Vue.js seems nice and I'm aware of a few nice lightweight dom abstractions (e.g. redom is nice).