Main Content

Announcing TypeScript 4.0

Today we are thrilled to announce the availability of TypeScript 4.0! This version of the language represents our next generation of TypeScript releases, as we dive deeper into expressivity, productivity, and scalability.

If you’re not familiar with TypeScript, it’s a language that builds on top of JavaScript by adding syntax for static types. The idea is that by writing down the types of your values and where they’re used, you can use TypeScript to type-check your code and tell you about mistakes before you run your code (and even before saving your file). You can then use the TypeScript compiler to then strip away types from your code, and leaving you with clean, readable JavaScript that runs anywhere. Beyond checking, TypeScript also uses static types to power great editor tooling like auto-completion, code navigation, refactorings, and more. In fact, if you’ve used JavaScript in an editor like Visual Studio Code or Visual Studio, you’ve already been using an experience powered by types and TypeScript. You can learn more about all of this on our website.

With TypeScript 4.0, there are no major breaking changes. In fact, if you’re new to the language, now is the best time to start using it. The community is already here and growing, with working code and great new resources to learn. And one thing to keep in mind: despite all the good stuff we’re bringing in 4.0, you really only need to know the basics of TypeScript to be productive!

If you’re already using TypeScript in your project, you can either get it through NuGet or use npm with the following command:

npm install -D typescript
You can also get editor support by

Downloading for Visual Studio 2019/2017
Installing the Insiders Version of Visual Studio Code or following directions to use a newer version of TypeScript
The 4.0 Journey
TypeScript is a core part of many people’s JavaScript stack today. On npm, TypeScript saw over 50 million monthly downloads for the first time in July! And while we recognize there’s always room for growth and improvement, it’s clear that most people coding in TypeScript really do enjoy it. StackOverflow’s most recent developer survey pins TypeScript as the 2nd most-loved language. In the most recent State of JS Survey, around 89% of developers who used TypeScript said that they would use it again.

It’s worth digging a bit into how we got here. In our past two major versions, we looked back at some highlights that shined over the years. For TypeScript 4.0, we’re going to keep up that tradition.

Looking back from 3.0 onward, there’s a dizzying number of changes, but TypeScript 3.0 itself came out with a punch. Unifying tuple types and parameter lists was a big highlight, enabling tons of existing JavaScript patterns on functions. The release also featured project references to help scale up, organize, and share across codebases. One small change that had a big impact was that 3.0 introduced a type-safe alternative to any called unknown.

TypeScript 3.1 extended the capabilities of mapped types to work on tuple and array types, and made it dramatically easier to attach properties to functions without resorting to TypeScript-specific runtime features that have fallen out of use.

TypeScript 3.2 allowed object spreads on generic types, and leveraged 3.0’s capabilities to better model meta-programming with functions by strictly typing bind, call, and apply. TypeScript 3.3 focused a bit on stability following 3.2, but also brought quality-of-life improvements when using union type methods, and added file-incremental builds under —build mode.

In the 3.4 release, we leaned farther into supporting functional patterns, with better support for immutable data structures, and improved inference on higher-order generic functions. As a big plus, this release introduced the —incremental flag, a way to get faster compiles and type-checks by avoiding a full rebuild on every run of TypeScript, without project references.

With TypeScript 3.5 and 3.6, we saw some tightening up of the type system rules, along with smarter compatibility checking rules.

TypeScript 3.7 was a very noteworthy release because it featured a rich combination of new type system features with ECMAScript features. From the type-system side, we saw recursive type alias references and support for assertion-style functions, both which are unique type-system features. From the JavaScript side, the release brought optional chaining and coalescing, two of the most highly demanded features for TypeScript and JavaScript users alike, championed in TC39 in part by our team.

Much more recently, 3.8 and 3.9 have brought type-only imports/exports, along with ECMAScript features like private fields, top-level await in modules, and new export * syntaxes. These releases also delivered performance and scalability optimizations.

We haven’t even touched on all the work in our language service, our infrastructure, our website, and other core projects which are incredibly valuable to the TypeScript experience. Beyond the core team’s projects is the incredible community of contributors in the ecosystem, pushing the experience forward, and helping out with DefinitelyTyped and even TypeScript itself. DefinitelyTyped had just 80 pull requests in 2012 when it first started, picking up on the tail end of the year. In 2019, it had over 8300 pull requests, which still astounds us. These contributions are fundamental to the TypeScript experience, so we’re grateful for such a bustling and eager community that’s been improving the ecosystem and pushed us to constantly improve.

What’s New?
All this brings us to 4.0! So, without further ado, let’s dive into what’s new!

- Variadic Tuple Types
- Labeled Tuple Elements
- Class Property Inference from Constructors
- Short-Circuiting Assignment Operators
- unknown on catch Clauses
- Custom JSX Factories
- Speed Improvements in build mode with —noEmitOnError
- —incremental with —noEmit
- Editor Improvements
- Convert to Optional Chaining
- /* @deprecated / Support
- Partial Semantic Mode at Startup
- Smarter Auto-Imports
- Our New Website!
- Breaking Changes”

Link to article