RxJS Functions (Part 11)

Corey Pyle
2 min readJan 18, 2019

--

identity

identity

https://rxjs.dev/api/index/function/identity

TL;DR

It’s a function that takes a single value as a parameter, and returns that same value. Literally. Here’s the function:

function identity(x) {
return x;
}

Use Case

I thought about this for a little bit, and the only think I can think of is that identity actually has a generic type argument. The function signature is identity<T>(x: T): T, so a function, that takes a param, T, and returns that same param. It seems like if you’re using TypesScript, and you want to quickly identify (aha!) what type is coming in from a vague source, you could do this:

Granted there are other, arguable more transparent, ways of accomplishing this, but this seems a reasonable thing to do with this function.

Thanks for reading. Stay tuned for Part 12, and be sure to check out my previous articles.

--

--