Microsoft has released a beta of TypeScript 5.6, an update to the strongly typed JavaScript variant that disallows nullish and truthy checks on syntax that never varies on nullishness or truthiness.
The TypeScript 5.6 beta, which follows last month’s production release of TypeScript 5.5, was announced July 26. TypeScript 5.6 can be accessed through NuGet or through NPM by running the npm install -D typescript@beta
command.
For disallowed nullish and truthy checks, the compiler now errors when it can syntactically determine that a truthy or nullish check will always evaluate in a specific way. Microsoft said “many, many bugs” could be caught this way. Some expressions still are allowed even if truthy or nullish. Specifically, true
, false
, 0
, and 1
are all still allowed despite always being truthy or falsy.
TypeScript 5.6 also introduces a native or built-in iterable type called BuiltinIterator
. It is defined as follows:
interface BuiltinIterator {
// …
}
TypeScript 5.6 also introduces a new intrinsic type called BuiltinIteratorReturn
and a new --strict
mode flag called --strictBuiltinIteratorReturn
. Whenever BuiltinIterator
types are used in places like lib.d.ts
, they are always written with a BuiltinIteratorReturn
type for TReturn
.
Other new features and improvements in TypeScript 5.6:
- A new compiler option is introduced,
--noCheck
, which allows developers to skip type checking for all input files. This avoids unnecessary type checking when performing semantic analysis necessary for emitting output files. - TypeScript 5.6 introduces a new feature called region-prioritized diagnostics or region-prioritized checking. Instead of just requesting diagnostics for a set of files, editors now can provide a relevant region of a given file. The idea is that this will typically be the region of the file that is currently visible to a user.
- Previously, computed properties marked with
override
did not correctly check for the existence of a base class member. Similarly, if developers usednoImplicitOverride
, they would not get an error if they forgot to add anoverride
modifier to a computed property. TypeScript 5.6 now correctly checks computed properties in both cases.