A lens is a getter/ setter for traversing a structure. A lens is also composable with other lenses, allowing traversing via a object or using projections. functional-lenses
Realize that the only dependency is the Object.assign from es6
import { idLens } from 'ts-lens';
type MyShape = {
a?:{
b: {
c: string
}
}
}
const withShape = idLens<MyShape>();
withShape.withAttrOr('a', { b: { c: ''}}).get({}) // ? { b: { c: ''}}
withShape.withAttrOr('a', { b: { c: ''}}).withAttr('b').withAttr('b').get({a:{
b: {
c: 'test
}
}}) // 'b'