For most of my programming career so far I’ve been using C# and working on desktop tools, and only dipping into more dynamic languages like javascript or python for fun hobby projects. That all changed recently when I started working on a new tool with a web UI (albeit hosted in electron for the moment) and a whole new bag of technologies. Some felt kinda familiar — React is a lot like WPF except without the two-way binding, which is an improvement, and Redux feels like the logical conclusion to a growing love of functional programming that I’d been developing over the years — but typescript caught me by surprise a little.

On the one hand C# is basically Java — but with a bunch of fun and useful ideas stolen from other languages like lambdas and LINQ, and a couple of new ideas like async/await added on top. Typescript feels like another step in that direction, with features like non-nullability and discriminated union types (coming …eventually to C#) already included with the language.

Typescript isn’t a direct upgrade from C#, though — it’s still fundamentally javascript at the core (one way of ‘compiling’ a typescript file is to just strip out all the typescript-specific annotations and ship what’s left) so there are always going to be some points where the types don’t line up quite right, or something that shouldn’t compile passes all the checks. But typescript still feels like it provides roughly 90% of C#’s typing power with around 50% of the effort (more on that later) and adds a bunch of bonuses on top.

The fact that typescript is built on top of javascript (rather than being a separate language that just compiles to javascript) does limit it in some ways. For example, extension methods are a long-requested feature that can’t be implemented right now because of the ways that trying to change the behaviour of javascript code depending on type information that might or might not be present can break quite easily. In addition, some proposed alternatives (like adding new operators to solve the problem) need to be avoided since having typescript and future ECMAscript proposals implement certain features slightly differently is a guaranteed recipe for pain.