DEV Community

Discussion on: Advanced TypeScript: reinventing lodash.get

Collapse
 
rexmingla profile image
Tim

Is there a way to avoid 3 levels of ternary operators? Even 2 levels is hard to read.

Collapse
 
tipsy_dev profile image
Aleksei Tsikov

Unfortunately, TS doesn't support conditional operators, so it's not possible to concatenate a few expressions with &&. The only way I know is to extract each ternary operator into a dedicated type, similar to how it is done with FieldWithPossiblyUndefined and IndexedFieldWithPossiblyUndefined. But to my mind, it adds even more boilerplate.