While TypeScript 4.1 is a planned upgrade to the popular programming language, now available as a beta release; it features template literal types and a multitude of enhancements. With the template literal type having the same syntax as template literal strings in JavaScript, except as it is used in type positions.
TypeScript 4.1 beta allows developers re-map keys in mapped types with a new as clause, and the new clause lets developers leverage features like template literal types to create new property names.
What's New in TypeScript 4.1 beta?
TypeScript 4.1 beta comes with a number of features, including a recursive conditional types capability, with some restrictions that are eased on conditional types, now able to immediately reference themselves within branches, making it easier to write recursive type aliases.
Albeit, Microsoft recommends that recursive types should be used sparingly, and of course, responsibly. Other additions to TypeScript 4.1 beta, includes:
- JSDoc tag @see now has better support in editors for JavaScript and TypeScript.
- React 17 framework’s jsxscode factory functions are supported via two new options for the jsxcode compiler, react-jsx and react-jsxdev options.
- The paths option can now be used without baseUrl, to avoid an issue in which poor paths are used by auto-imports.
- In TypeScript 4.1 beta, checkJs now implies allowJs, which fixes the situation in which starting a checked JavaScript project required both allowJs and checkJs, which resulted friction.
Additionally, in the breaking change, members marked as abstract can't be marked as async and resolve parameters are no longer optional in Promise. And there is a new flag, --noUncheckedIndexedAccess, that provides a node where every property access or indexed access is considered potentially undefined.
The flag is capable of catching out-of-bounds errors, though it might be noisy for a lot of code. And it is not automatically enabled by the --strict flag.
How to Get Started with TypeScript 4.1 beta
If you want to give TypeScript 4.1 beta a spin, it can be accessed via NuGet or NPM, using the below command:
npm install typescript@beta
And the release candidate for TypeScript 4.1 is due in October, while TypeScript 4.0, which is the current major release, arrived in August.
No comments