This content originally appeared on DEV Community and was authored by Kristiyan Velkov
TypeScript 5.1 introduced several new features and improvements.
Here's a summary of what's new in TypeScript 5.1:
- Easier Implicit Returns for undefined-Returning Functions: TypeScript 5.1 allows undefined-returning functions to have no return statement, simplifying the syntax.
function doSomething(): undefined {
// Function body
}
// In TypeScript 5.1, you can omit the explicit 'return undefined;'
function doSomething(): undefined {
// Function body
}
- Unrelated Types for Getters and Setters: TypeScript now allows get and set accessor pairs to specify different types.
class Example {
private _value: boolean = false;
get value(): boolean {
return this._value.toString();
}
set value(newValue: string) {
this._value = newValue === 'true';
}
}
- Decoupled Type-Checking Between JSX Elements and JSX Tag Types: TypeScript 5.1 allows JSX libraries to accurately describe what JSX components can return, making it possible to use asynchronous server components in libraries like React.
// Previously in TypeScript versions before 5.1
const myComponent: JSX.Element = <MyComponent prop1="value" prop2={42} />;
// With TypeScript 5.1, you can omit the explicit JSX tag type
const myComponent = <MyComponent prop1="value" prop2={42} />;
- Namespaced JSX Attributes: TypeScript now supports namespaced attribute names when using JSX, allowing more flexibility in attribute naming.
// Previously in TypeScript versions before 5.1
const myComponent = <MyComponent jsx:prop1="value" />;
// With TypeScript 5.1, you can use namespaced JSX attributes
const myComponent = <MyComponent jsx:prop1="value" />;
typeRoots Are Consulted In Module Resolution: TypeScript's module resolution strategy now considers the specified typeRoots when resolving package paths.
Linked Cursors for JSX Tags: TypeScript now supports linked editing for JSX tag names, allowing simultaneous editing of multiple locations.
Snippet Completions for @param JSDoc Tags: TypeScript provides snippet completions when typing out the @param JSDoc tag, improving the documentation process.
In addition to these new features, TypeScript 5.1 includes optimizations to improve performance and addresses some breaking changes related to the minimum runtime requirements (ECMAScript 2020 and Node.js 14.17).
Please note that this information is based on the provided announcement, and you can refer to the official TypeScript documentation or release notes for more detailed information about TypeScript 5.1. or this good blog post.
If you like my work and want to support me to work hard, please donate via:
Revolut website payment or use the QR code above.
Thanks a bunch for supporting me! It means a LOT 😍
This content originally appeared on DEV Community and was authored by Kristiyan Velkov
Kristiyan Velkov | Sciencx (2023-06-03T09:29:44+00:00) TypeScript – 5.1 is here! -What’s new ?. Retrieved from https://www.scien.cx/2023/06/03/typescript-5-1-is-here-whats-new/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.