Last JavaScript-Based TypeScript Enters Beta
The final version of TypeScript to be written in JavaScript has now entered its beta phase. This release marks a significant transition toward a new implementation model for the language, which may require library maintainers to update internal build scripts and type definitions for forward compatibility.
- Performance optimizations in this beta include faster type-checking and more efficient incremental builds, achieved through improved algorithms and better caching of type information across multiple runs. Caching contextual types from discriminated unions alone shaved 250ms off of compiling the TypeScript compiler itself. - For years, the TypeScript compiler has been "self-hosted," meaning it's written in TypeScript and then compiled to JavaScript. This process relies on a "Last Known Good" (LKG) version of the compiled JavaScript compiler to compile the newest TypeScript code. - The new `isolatedDeclarations` flag allows for the generation of type declaration files (.d.ts) without performing a full type check of the source files. This can significantly speed up build processes for libraries and monorepos by allowing declaration emit to happen in parallel with type checking. - A key feature is "inferred type predicates," which allows TypeScript to automatically recognize functions that act as type guards without explicit `is` annotations. This reduces boilerplate code and improves readability, for example, when filtering an array for a specific type. - Control flow analysis is now more precise for constant indexed accesses (e.g., `obj[key]`). This allows the compiler to narrow types more accurately in situations where an object's property is accessed via a constant, reducing the need for manual type assertions. - The beta introduces built-in syntax validation for regular expressions, catching common errors at compile time rather than at runtime. It will also error if a regular expression uses features newer than the configured ECMAScript target. - This version adds support for new ECMAScript Set methods, including `union`, `intersection`, and `difference`, keeping TypeScript aligned with the latest JavaScript standards.