Languages
[Edit]
EN

React / TypeScript - generic arrow function in *.tsx / Extended TypeScript

4 points
Created by:
Emrys-Li
580

In this quick article we are going to look at how to create generic arrow function in *.tsx / Extended TypeScript.

Quick solution:

const func = <T extends unknown>(arg: T) => { return arg; };

Alternative solutions:

const func = <T extends {}>(arg: T) => { return arg; };
const func = <T extends any>(arg: T) => { return arg; };
const func = <T,>(arg: T) => { return arg; };
const func = function<T>(arg: T) { return arg; };

 

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join