Microsoft tickles devs with a Release Candidate for TypeScript 3.1
Type declarations? What wizardry is this?
While Windows Insiders get all misty eyed about the words “Release Candidate”, developers can start getting serious about version 3.1, since its release is not far away.
TypeScript is an open source programming language, and was one of the early signs that changes were afoot within Microsoft when it made its first appearance nearly six years ago.
There is good news (assuming Types do not scare you) and bad news in the Release Candidate of TypeScript 3.1. The good news is the addition of support for mappable tuple and array types, which takes the existing mappable object types functionality in TypeScript and applies it to arrays and tuples.
As Daniel Rosenwasser, TypeScript Program Manager at Microsoft, observed: “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.” Which indeed it does, although having played with the functionality we’re a little surprised it hasn’t always worked this way as opposed to the nasty (but technically consistent) error thrown in earlier versions of TypeScript.
A second major update, which will ease the pain of migrating to TypeScript, deals with the problem of namespaces. Namespaces don’t play well with the likes of
const declarations, which can make getting code from the likes of untyped React into a TypeScript world headache-inducing. The fix has been to make the type-checker a little cleverer – as Rossenwasser explained: “In TypeScript 3.1, 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.”
Unfortunately, 3.1 also breaks some stuff, so caution does need to be exercised before you fire it up. A large number of vendor-specific types have disappeared from the built-in
lib.d.ts library. To be fair, this is no bad thing and an inevitable consequence of working with Web IDL files from the DOM specification. If you absolutely must have those types available, then the advice is to add the declarations locally. Or maybe stop supporting specific browsers, hmm?
More annoyingly, narrowing functions have seen some changes which could cause errors to be thrown and require some tweaking to the syntax.
The final release of 3.1 should occur later this month, which will mean we only have until November to wait before
BigInt finally makes an appearance in the language. ®
Sponsored: Becoming a Pragmatic Security Leader