The Origins of TypeScript: Adding a Type System to JavaScript

Matt George

Fractional CTO · Founder of Injuria.ai

JavaScript was designed to be forgiving. You can add a number to a string, call a function with the wrong arguments, or reference a property that does not exist, and the language will do its best to keep going. That forgiveness is wonderful when you are adding a bit of behavior to a page. It becomes a liability when fifty engineers share a single application with hundreds of thousands of lines, and a typo that another language would catch instantly ships to production instead. TypeScript was built to fix that without asking anyone to leave JavaScript behind, and that last part is the entire reason it succeeded where a dozen smarter-sounding ideas failed.

The problem TypeScript was built to solve

By the early 2010s, JavaScript was no longer a scripting toy. Teams were building whole products in it, on the front end with early frameworks and on the back end with Node. The tooling had not caught up. Editors could not reliably tell you what a function expected or what an object held, because the language recorded none of that. Refactoring a large JavaScript codebase meant searching for text and praying. The bigger the project, the harder the language's own flexibility worked against you. Microsoft hit this wall on its own large web applications and decided to address it head on.[2]

A superset, not a replacement

The key decision in TypeScript is that it is a superset of JavaScript. The compiler will parse any valid JavaScript, so you adopt the language by renaming a file and adding types where they help, not by rewriting anything.[1] It is worth being precise about what "every JS file is a TS file" really means, because it is often oversold. Rename a messy .js file to .ts with strict checking on and the compiler will usually light up with errors immediately. That is the point, not a failure, and the config knobs exist to control exactly how much it complains while you migrate.

The types exist only during development and compilation. They are erased before the code runs, so they add no runtime cost and change no runtime behavior.[1] A typed function is ordinary JavaScript with a few annotations.

function greet(user: { name: string }): string {
  return `Hello, ${user.name}`;
}

That signature tells your editor, your teammates, and the compiler exactly what greet needs and returns. Call it with the wrong shape and you get an error before anything runs. Just as important, you rarely have to write types everywhere, because the compiler infers most of them from how you assign and use values. Good inference is the difference between a type system that feels like help and one that feels like paperwork, and TypeScript leaned hard on inference from the start.

The person behind it

TypeScript was created at Microsoft under Anders Hejlsberg, and his history explains a great deal about the result.[8] Hejlsberg designed Turbo Pascal, led the Delphi project, and was the chief architect of C#.[4] He had spent decades building statically typed languages with first-class tooling. Putting him in charge of a type system for JavaScript meant the project began with deep experience in the exact problem it was trying to solve. It started internally around 2010 under the codename Strada and was announced publicly on October 1, 2012.[2][3]

Structural typing: if it fits, it works

TypeScript uses structural typing, which suits JavaScript's culture perfectly. What matters is the shape of a value, not the name of its type. If an object has the properties a function needs, it is accepted, regardless of where it came from or what it was formally declared to be.[1] This is duck typing with a safety net, and it matches how JavaScript developers already thought. It let TypeScript describe messy existing libraries accurately instead of forcing everyone into a rigid class hierarchy.

The team also chose to be pragmatic rather than strictly correct. The type system has escape hatches, chiefly the any type, which turns checking off for a value when you need it to. Purists dislike this, and they are missing the point. The any hatch is the single feature that made a half-migrated codebase compile, and a type system you can adopt gradually beats a sound one you cannot adopt at all.

The turning point: Angular, and a rival that defected

TypeScript grew steadily, then got the endorsement that changed everything. In March 2015, Google announced that Angular 2, a ground-up rewrite of one of the most widely used front-end frameworks, would be built in TypeScript.[5] The backstory is better than the headline. Google had been building its own typed dialect of JavaScript, called AtScript, for Angular 2. Microsoft agreed to add the decorator and metadata features Angular needed, Google folded AtScript into TypeScript, and a would-be competitor became the language's most important customer.[5] A major framework betting on TypeScript told the rest of the industry the language was safe to adopt.

The ecosystem had quietly started filling in even earlier. DefinitelyTyped, a community repository of type descriptions for existing JavaScript libraries, was created by Boris Yankov in late 2012, within weeks of the first public release.[6] That meant you could pull in a popular untyped package and still get checking and autocomplete, which removed one of the biggest early objections. The editor experience, powered by the TypeScript language service, became the real reason people stayed. Autocomplete that actually knows your code, and refactors you can trust, are very hard to give up once you have them.

Why it survived when others did not

Plenty of projects tried to put types on JavaScript or replace it with something safer, and most died for the same reason: they asked teams to switch all at once, or they invented their own runtime that drifted away from the web platform. TypeScript made two bets that avoided both traps. The first was gradual adoption.[9] A tsconfig.json lets a team turn on loose checking, migrate the risky files first, and tighten strict settings over months, with allowJs letting typed and untyped files coexist the whole time.[10] The second, and the one people underrate, was a deliberate pledge to track ECMAScript rather than compete with it.[7] TypeScript's job became adding static types and then getting out of the way, letting new JavaScript features arrive through the standard. That discipline is why TypeScript code is still just JavaScript with annotations a decade later, instead of a diverging language its users would eventually have to escape.

What it does not skimp on is the type system itself. Generics, union and intersection types, and mapped and conditional types exist because accurately describing a dynamic, duck-typed library turns out to require a genuinely powerful type language.[11] TypeScript is pragmatic at the edges and surprisingly deep in the middle, and both are on purpose.

The humility that beat the better ideas

TypeScript is now the default for serious JavaScript work. React, Vue, Node tooling, and most new projects assume it, Deno runs it directly, and much of the npm ecosystem ships type definitions in the box. The interesting thing is everything it refused to do. It did not try to replace JavaScript, fix its quirks, or drag the ecosystem onto a new runtime. It accepted the language as it is, warts and all, and added a layer that makes large codebases survivable. Engineers love to admire the clever, clean-slate solution. TypeScript is a reminder that the winning move is usually the humble one that meets people exactly where they already are, and that the discipline to stay boring is its own kind of design genius.

Sources (11)
  1. TypeScript Handbook (official documentation)
  2. Microsoft, "Ten Years of TypeScript" (TypeScript blog)
  3. ZDNet, "Microsoft takes the wraps off TypeScript" (October 2012)
  4. Anders Hejlsberg (Wikipedia)
  5. Microsoft, "Angular 2: Built on TypeScript" (March 2015)
  6. DefinitelyTyped (GitHub repository)
  7. ECMA-262, the ECMAScript Language Specification
  8. David Pine, Learning Blazor ("O'Reilly Media, Inc.", 2022)
  9. Maurizio Gabbrielli, Simone Martini, Programming Languages: Principles and Paradigms (Springer Nature, 2023)
  10. Ben Grynhaus, Jordan Hudgens, Rayon Hunte, The TypeScript Workshop (Packt Publishing Ltd, 2021)
  11. Sebastien Dubois, Alexis Georges, Learn TypeScript 3 by Building Web Applications (Packt Publishing Ltd, 2019)

Recommended reading

The Origins of Go: Simplicity as a Feature8 min readGo was a reaction. Three veteran engineers at Google, frustrated by slow builds and growing complexity, built a language that left features out on purpose. That restraint made it the language of modern cloud infrastructure.The Origins of Java: Write Once, Run Anywhere7 min readJava was built to run on television set-top boxes. That market never arrived, but the idea underneath it, code that runs anywhere without changes, made Java the language of enterprise software and Android. Here is the story.The Origins of PHP: The Accidental Language That Runs Much of the Web6 min readPHP was never meant to be a programming language. It started as a few tools one developer wrote to track visits to his resume, survived an existential threat from Facebook, and still runs a large share of the web. Here is how.The Origins of Ruby: A Language Designed for Programmer Happiness6 min readMost languages optimize for the machine or the problem. Ruby set out to optimize for the person writing the code. That unusual goal, plus one framework, turned it into the language behind a generation of startups.The Origins of C#: Microsoft's Answer to Java5 min readC# was born out of a lawsuit. Blocked from extending Java, Microsoft built its own modern language, had it standardized so no one could call it a cage, and spent two decades turning it into a fast, open, cross-platform tool.The Origins of SQL: The Language That Refused to Die6 min readSQL is more than fifty years old, has been declared obsolete more than once, and still runs the data layer of nearly every web application. Here is where it came from, the rival language it beat, and why nothing has managed to replace it.