Ailrun / typed-f

Typed functional programming utilities
MIT License
20 stars 2 forks source link

fix(lens): fix undefined access of focusTo and fromKey #40

Closed Ailrun closed 5 years ago

Ailrun commented 5 years ago

Description

When you have something like following,

interface X {
  key?: {
    inner: number;
  };
}

const x: X = {};
const xLens: LensSProxy<X, X> = new LensGenerator<X>().byProxy();
xLens
  .key
  .inner
  .set()(x)(5);

last statement will give you error saying <xxx> is undefined. This is because when lens try to set inner, lens try to get a current value of key, which is undefined, and try to set the 5 to its inner property.

This is not a best solution (since this can break types if there is more than one properties to the key which is currently undefined), just a hot fix for lens problem.