TypeScript – 5.1 is here! -What’s new ?

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
}
Enter fullscreen mode

Exit fullscreen mode

  • 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';
  }
}
Enter fullscreen mode

Exit fullscreen mode

  • 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 = ;

// With TypeScript 5.1, you can omit the explicit JSX tag type
const myComponent = ;
Enter fullscreen mode

Exit fullscreen mode

  • 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 = ;

// With TypeScript 5.1, you can use namespaced JSX attributes
const myComponent = ;
Enter fullscreen mode

Exit fullscreen mode

  • 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.


Image description

linkedin


Image description

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 😍


Setup FastAPI Debugger in PyCharm With Docker

The key is running only 1 worker when start uvicorn Content For local Python app development, use a…

You May Also Like