2 min read

Last week, Daniel Rosenwasser, Program Manager for TypeScript, announced the release of TypeScript 3.4. This release comes with faster subsequent builds with the ‘–incremental’ flag, higher order type inference from generic functions, type-checking for globalThis, and more.

Following are some of the updates in TypeScript 3.4:

Faster subsequent builds

TypeScript 3.4 comes with the ‘–incremental’ flag, which records the project graph from the last compilation. So, when TypeScript is invoked with the ‘–incremental’ flag set to ‘true’, it will check for the least costly way to type-check and emit changes to a project by referring to the saved project graph.

Higher order type inference from generic functions

This release comes with various improvements around inference, one of the main being functions inferring types from other generic functions. At the time of type argument inference, TypeScript will now propagate the type parameters from generic function arguments onto the resulting function type.

Updates in ReadonlyArray and readonly tuples

Now, using read-only array-like types is much easier. This release introduces a new syntax for ReadonlyArray that uses a new readonly modifier for array types:

function foo(arr: readonly string[]) {
arr.slice();        // okay
arr.push("hello!"); // error!
}

TypeScript 3.4 also adds support for readonly tuples. To make a tuple readonly, you just have to prefix it with the readonly keyword.

Type-checking for globalThis

This release supports type-checking ECMAScript’s new globalThis, which is a global variable that refers to the global scope. With globalThis, you can access the global scope that can be used across different environments.

The globalThis variable provides a standard way for accessing the global scope which can be used across different environments.

Breaking changes

As this release introduces few updates in inference, it does come with some breaking changes:

  • TypeScript now uses types that flow into function calls to contextually type function arguments.
  • Now, the type of top-level ‘this’ is typed as ‘typeof globalThis’ instead of ‘any’. As a result, users might get some errors for accessing unknown values on ‘this’ under ‘noImplicitAny’.
  • TypeScript 3.4 correctly measures the variance of types declared with ‘interface’ in all cases. This introduces an observable breaking change for interfaces that used a type parameter only in keyof.

To know the full list of updates in TypeScript 3.4, check out the official announcement.

Read Next

An introduction to TypeScript types for ASP.NET core [Tutorial]

Typescript 3.3 is finally released!

Yarn releases a roadmap for Yarn v2 and beyond; moves from Flow to Typescript