TypeScript 6 release
What's new with TypeScript 6? Learn about the breaking changes, better and stricter defaults and a few utilities.
TypeScript 6.0 just dropped! While it’s not a major upgrade, it acts as a transition release between TypeScript 5.9 and 7.0 and it will ensure you’re ready for the massive performance gains you’re likely to see in TypeScript 7.0.
What I like the most with this release is the effort from the TypeScript team to simplify TypeScript configurations, evolve their defaults to sound standards to reflect the ecosystem’s direction as well as gradually move to stricter defaults.
Breaking Changes and Deprecations
Let’s start with the stuff you want to get out of the way:
types now defaults to []
This is likely to affect your projects. For example if you use TypeScript for local scripts or a server application, you will want to add "types": ["node"] and maybe a few others to your config file.
rootDir now defaults to .
With this change, it is now recommended to set your rootDir explicitly, for example to "rootDir": "./src"
baseUrl option is deprecated
This option was mostly used together with paths. If you relied on baseUrl as a prefix for path, you have to remove baseUrl and add the prefix to your path entries.
strict is now true by default
This is part of the changes towards good defaults for most new projects. This will implicitely turn on multiple strict flags such as noImplicitAny and noImplicitThis.
module now defaults to esnext
TypeScript is embracing the ecosytem’s move to ESM as the default module format.
target now defaults to current-year ES version
This makes TypeScript follow ECMAScript spec versions releases.
noUncheckedSideEffectImports is now true by default
This change contributes to making TypeScript more strict by default and provide stronger runtime guarantees.
asserts keyword on Imports is now replaced with “with”
The following code is now deprecated:
import data from "./data.json" asserts { type: "json" }You have to use the with syntax:
import data from "./data.json" with { type: "json" }What’s new with TypeScript 6.0 update?
es2025 option for target and lib
This is minor as they are no major new JavaScript language features in es2025. It mainly moves some declarations from esnext to es2025 such as Promise.try, Iterator and Set methods.
Types for getOrInsert for upset operations
This is a small convenience utility to simplify the recurring pattern of checking if an item is in Map and if not, insert a default value.
For example the consider the code below for appending a value to an array in a map:
const citiesTemperatures = new Map<string, number[]>();
if (!citiesTemperatures.has("Berlin")) { citiesTemperatures.set("Berlin", []);}
citiesTemperatures.set("Berlin", [...citiesTemperatures.get("Berlin")!, 10]);Now we can simplify the code to:
const citiesTemperatures = new Map<string, number[]>();
citiesTemperatures.set("Berlin", [...citiesTemperatures.getOrInsert("Berlin", []), 10]);And the cherry on top is that we no longer have a type quirk which forced us to tell TypeScript that the key was guaranteed to exist!
Read more about getOrInsert on MDN
Types for Temporal
Working with dates and timezones is always a challenge, in fact many of us are using third party librairies to ease the pain. Thanks to the new Temporal API, some well designed datetime utility functions are being adopted as a standard. Here is a quick glimpse with timezones:
const meetingTime = Temporal.ZonedDateTime.from("2021-08-01T12:00[America/New_York]");
const meetingTimeInBerlin = meetingTime.withTimeZone("Europe/Berlin");You can learn more about the Temporal API on MDN
What’s next for TypeScript
If you were not already aware, the team is working on a new codebase for TypeScript written entierely in Go which promises massive speed increases for your TypeScript compilation times. Benchmarks are reported around a 10x speed improvements which is quite impressive!
Here is the TypeScript official release blog post, it’s a bit long but extremely well written and worth the read if you have the time.
If you’re looking for TypeScript configuration recommendations with a set of good and strict defaults, I wrote a guide here.