DEV Community

Orfeo
Orfeo

Posted on

Simplifying Async Function Definitions in TypeScript

When working with asynchronous code in TypeScript, you usually define functions like this:

function complete(event: AutoCompleteCompleteEvent) {
  // Your code
}
Enter fullscreen mode Exit fullscreen mode

However, you can also define the same function as an async arrow function expression, which can be useful when assigning functions as values or passing them as props, callbacks, or event handlers.

Here’s how that looks:

const complete = (event: AutoCompleteCompleteEvent) => {
  // Your code
};
Enter fullscreen mode Exit fullscreen mode

Async version:

const complete = async (event: AutoCompleteCompleteEvent) => {
  // Your code
};
Enter fullscreen mode Exit fullscreen mode

Notice the differences:

  • No function keyword — you use an arrow (=>) instead.
  • The async keyword stays before the parameter list.
  • This pattern allows you to define asynchronous handlers inline or as part of an object or class property.

This syntax is particularly handy in frameworks like React or Vue where you often need to bind methods to components or use closures. It keeps your function definitions compact and consistent with modern JavaScript style.

Top comments (0)