I implemented the equivalent of “?.” In typescript with a function callled safeRetrieve(descend into the field only if the object is not null).

We could not update typescript, so I just created this function and it made me used to use ‘keyof T’ as a parameter type… I still feel very satisfied after I use this approach with anything because it really feels like using typescript correctly!

Add Comment