Effect CommunityEC
Effect Community3y ago
3 replies
DjebbZ

Extracting T from Option<T> in TypeScript

Hello, I have an Option<T>, if (isNone(x)) { return ... } narrows the None case, so TypeScript successfully tell me that x is a Some<T> after the if. How can I extract T ? All the helpers I find in the
Option
, like getOrElse, getOrNull will give me back T | null or T | somethingElse. I just want T and it's safe to do at this point. It might (or not) help to know that T is a union of 2 types X | Y.
Was this page helpful?