TypeScript 3.1 arrives with some important breaking changes in tow

One of the fastest ascending programming languages is here with another release. TypeScript 3.1 is out and it features some interesting updates. Let’s take a look.
About three months after the last update, one of the fastest ascending programming languages is back with another release – TypeScript 3.1 is out and loud!
The new release includes some important updates and new features, as well as some breaking changes.
Let’s take a closer look at the highlights of TypeScript 3.1.
Mappable tuple and array types – Rather than introduce a new concept for mapping over a tuple, mapped object types now just “do the right thing” when iterating over tuples and arrays. This means that if you’re already using existing mapped types like Partial
or Required
from lib.d.ts
, they automatically work on tuples and arrays now.
SEE ALSO: TypeScript’s meteoric rise on the charts
Easier properties on function declarations – For any function declaration or const
declaration that’s initialized with a function, the type-checker will analyze the containing scope to track any added properties.
Version redirects for TypeScript via typesVersions
– In the case of using Node module resolution in TypeScript 3.1, when TypeScript cracks open a package.json
file to figure out which files it needs to read, it first looks at a new field called typesVersions
. A package.json
with a typesVersions
field might look like this:
{ "name": "package-name", "version": "1.0", "types": "./index.d.ts", "typesVersions": { ">=3.1": { "*": ["ts3.1/*"] } } }
This package.json tells TypeScript to check whether the current version of TypeScript is running.
Matching behavior – The way that TypeScript decides on whether a version of the compiler & language matches is by using Node’s semver ranges.
Multiple fields – typesVersions
can support multiple fields where each field name is specified by the range to match on.
Refactor from .then()
to await
– TypeScript 3.1 now has a refactoring to convert functions that return promises constructed with chains of .then()
and .catch()
calls to async
functions that leverage await
.
But we are not done, there are also a couple of breaking changes you should keep in mind for TypeScript 3.1.
Vendor-specific declarations removed – Now can generate parts of lib.d.ts (and other built-in declaration file libraries) using Web IDL files provided from the WHATWG DOM specification. While this means that lib.d.ts will be easier to keep up-to-date, many vendor-specific types have been removed.
Differences in narrowing functions – Using the typeof foo === "function"
type guard may provide different results when intersecting with relatively questionable union types composed of {}, Object
, or unconstrained generics.
Getting started
You can get started with the latest version of TypeScript through NuGet or via npm by running
npm install -g typescript