Languages
[Edit]
EN

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

4 points
Created by:
Marcin
19340

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; };

 

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