Microsoft's Typescript, a popular programming language known for its static typing, has recently released its latest update, version 5.0. This update comes with exciting new features that are sure to delight the developer community.
Decorators : New,Easy and Quick!
In TypeScript, Decorators can be used to add custom behavior or metadata to a class, method, property, or function parameter without changing its underlying structure. Current version includes new decorator standards that allow users to reuse the customized classes and their members.
Although experimental decorators have helped to some extent they always required the opt-in compiler flag —experimentalDecorators and were based on an older version.
Developers may write code that is clearer and easier to maintain while also having the option to tweak classes and their members in a reusable way thanks to the new decorators proposal in TypeScript 5.0.
Automagic switch/case completions:
Here is another exciting new feature for code-completions.
TypeScript 5.0, while creating a switch statement,now recognizes whether the value being checked has a literal type,If so it will provide a code completion that builds upon each case that is yet to be discovered.
Const Type Parameters
Till now, in order to achieve the necessary inference, API authors have often had to recommend adding as const in certain locations in previous versions.
This can be difficult and simple to overlook. You can now add a const modifier to a type parameter declaration in TypeScript 5.0 to make const-like inference the default.
type HasNames = { names: readonly string[] };
function getNamesExactly<const T extends HasNames>(arg: T): T["names"] {
// ^^^^^
return arg.names;
}
// Inferred type: readonly ["Alice", "Bob", "Eve"]
// Note: Didn't need to write 'as const' here
const names = getNamesExactly({ names: ["Alice", "Bob", "Eve"] });
If you develop libraries, you may have instructed your users to write "as const" when calling functions.
You can specify which values should be given literal & read-only types using 'const' type arguments.
enum are now Union enums
enums were just a collection of identical-typed numeric constants when TypeScript first introduced them.
When TypeScript encountered these problems, it would subtly abandon the new enum approach. Giving up all the benefits of literal types and unions included doing that.
By designating a distinct type for each computed member, TypeScript 5.0 is able to convert all enums into union enums. As a result, all enums can now be constrained and contain references to their members as types.
Introducing --moduleResolution bundler
With the introduction of "—moduleResolution bundler" in TypeScript 5.0, most current bundlers and loaders may now be modeled.
It recognises classic Node-style resolution while adhering rules to exports, imports, and other constraints.
Case-Insensitive Import Sorting in Editors
Previously, TypeScript believed the import list to be sorted since it was performing a straightforward case-sensitive sort. Developers who favored a case-insensitive ordering or who utilized tools like ESLint, which demand a case-insensitive ordering by default, may find this to be a source of issue.
Case sensitivity is now automatically detected by TypeScript. As a result, TypeScript and tools like ESLint usually won't "argue" over how to arrange imports properly.
Supporting Multiple Configuration Files in extends
Moreover, TypeScript 5.0 enables the mixing and matching of parameters from several "tsconfig.json" files.
The extends field can now accept multiple entries thanks to Typescript 5.0, which increases versatility in this area. In this configuration file, for instance:
Simplifying Process- Optimizing Speed - Rationalizing Size
TypeScript 5.0 is much faster.
With TypeScript 5.0, you may expect seeing between 10% and 20% of your build times evaporate!
Moreover, TypeScript is lighter! TypeScript 5.0 now occupies roughly 41% less space when unzipped from npm than TypeScript 4.9!
Overall,there is no doubt that TypeScript 5.0 has many exciting features to offer for developers.
Visit Software Development Company in US - Mako IT Lab to know more about tech-updates and industry trends.
References :
Announcing TypeScript 5.0 - TypeScript (microsoft.com)