Alternatives to TypeScript
AI Generated Video Summary
This Talk explores alternatives to TypeScript such as Clojure, Flow, and Hagel, highlighting their unique features and syntax. Flow and Hagel make finer distinctions between types and prioritize safety. TypeScript offers quick fixes for inferring types. Hagel aims for fewer type annotations and increased safety. These alternatives can provide insights and understanding of TypeScript.
1. Introduction to Alternatives
Hello, and welcome to my Talk, Alternatives to TypeScript. While I'm a big fan of TypeScript, no language exists in a vacuum. They all influence and inspire each other. Who am I? My name is Ashley Claymore and I work as a software engineer at Bloomberg. I've been using TypeScript for six years now, meaning I've got to see how much it's evolved. I've also contributed to TypeScript and I'm a TC39 delegate.
Okay, there's a big block of code here and don't worry about trying to read it. The important thing I'm trying to show is that in this whole snippet, it's syntactically valid in all three, Hagel, Flow and TypeScript. This tells us they all have a similar look and feel to them, but they do diverge and for the rest of this talk, what I'm going to do is just going to give you a flavor of how they are different to each other. So for example, in Flow and Hagel, they're generic type constraints. They use a colon instead of an extends keyword. They also have this prefix union question mark operator, and they also allow parameter names to be emitted in function types. Flow primarily and Hagel exclusively use their built-in utility types when you're doing type manipulation instead of having some extra additional dedicated syntax for doing that. And then, these utility types are implemented directly in their compilers. If you compare that to the TypeScript approach, where almost all of the utility types are aliases for the syntactic way of doing that type manipulation, things like map types and conditional type syntax. If I create a type hierarchy diagram, that lets us compare a few differences in how the systems model their types. One time that Hagel is taking a different approach is that it doesn't have an any type. The closest you can get is to the safer unknown type. Flow does have any, and their unknown type, they call that mixed instead. And Flow also calls their bottom type empty instead of never. Where TypeScript has both a void and an undefined type, Flow only has void and Hagel only has undefined. TypeScript also put their object literal type much higher up, up above the primitives, whereas Flow and Hagel make this finer distinction between what's a primitive, array, a function, and what object literal types describe. I have an example of that coming up. Firstly, Flow and Hagel have this concept that types can be closed by default.
2. Type Checking and Safety
In this example, if additional properties are passed in, it's treated as an error. To allow additional properties, add dot, dot, dot to the type. Flow and Hagel have finer type distinctions. They flow types from call sites, even without annotations. Hagle checks functions by looking at their implementation. TypeScript offers quick fixes for inferring types. Flow and Hagle strive for safety, making subtle distinctions. Hagle's goal is fewer type annotations and increased safety. It infers fixed-length arrays. Other tools' approaches can help understand TypeScript.
So, in this example, because I only mentioned the path property, when values are passed in that have additional properties, that's treated as an error, even if it's not done inline. If you're okay with having additional properties passed in, you need to add dot, dot, dot to the type. That tells us it's now an open type.