Recently, I've been delving into Facebook's immutable library and exploring their TypeScript bindings.
Consider this snippet of code:
const list: User[] = ...;
list.map(user => ...)
The lambda parameter user
correctly has the type of User
.
However, when I incorporate immutable's List
and wrap my array like this:
import {Map, List} from "immutable";
List(list).map(user => ...)
To my surprise and confusion, the lambda parameter user
is now inferred as User | undefined
. Even trying to specify the type with List<User>(list)
doesn't resolve the issue.
Looking at the library's .d.ts file, we see the following definition:
export function List<T>(array: Array<T>): List<T>;
So what could be causing this unexpected behavior?