TypeScript 4 — Quick Digest

Luka Ušalj
brainit
Published in
4 min readSep 23, 2020

TypeScript is a superset of JavaScript that adds optional typing to the language. This help us catch errors more quickly while writing new features or refactoring old ones.

Microsoft team is continuously working on improving the language. Let’s see which new capabilities have they brought to the Typescript in the latest release, 4.0!

Faster startup time

Long startup time has been a known issue for a large codebases. It used to take between 20 seconds and 1 minute until Visual Studio Code became responsive because language server needed to parse the entire project, it’s dependencies, dependencies of dependencies etc…

Here comes into the play so-called partial editing mode. It looks which file you are on and parse that first, which results in responsive editing after 2 to 5 seconds for a larger projects.

Build improvements

Recently, Typescript introduced incremental flag which allows you to skip recompiling parts of your code that have already been compiled. In Typescript 4, it can be used along with --noEmit and --noEmitOnError flag.

Breaking changes

There is actually one. Using delete operator with a non-optional operand will result in a compile error, if strictNullChecks flag is enabled in compilerOptions.

Smarter auto-imports

Auto imports are powerful. However, in some cases, when you tried to auto-import from the package that was written in Typescript, it just didn’t work. You had to first write your import manually. After that, auto-import worked seamlessly.

In the newest release TypeScript is doing some extra work parsing your dependencies and peerDependencies defined in package.json in order to have that information from your beloved package right away.

Class property inference

Previously, area would implicitly be of any type. But now, control flow analysis can determine the types of properties in classes if noImplicitAny flag is enabled in compilerOptions.

@deprecated support

TypeScript’s editing support now recognises when a declaration has been marked with a /** @deprecated * JSDoc comment. In Visual Studio Code, deprecated values will be displayed with a strike-though style.

New assignment operators

Three new assignment operators have been added: &&=, ||=, and ??= as a coding enhancement.

'unknown' on catch clause bindings

Since the beginning days of TypeScript, catch clause variables have always been typed as any. Now, they can be specified as unknown, with unknown being safer than any because it reminds developers that they must perform type-checking before operating on their values.

Variadic tuple types

Variadic tuple types provide the ability for tuple types to have spreads of generic types that can be replaced with actual elements through type instantiation. Also, the inference process for rest parameters and rest tuple elements is improved.

Variadic tuple types enable new patterns, especially around function composition.

Labeled tuple types

Tuple types can now provide element descriptors.

If you want to dig deeper in any of this topics, you can do it on the link below where all the features are explained in more detail.

Have fun and happy coding!

--

--