Lodash set with Typescript

Viewed 39

we're using Lodash/fp and we're running into an issue with the set function, if we assign a new property or replace one in an object, the type doesn't match the expected outcome. Therefore, validation is impossible. Example:

const obj = { foo: 1 };
const newObj = set('bar')(2)(obj);

The type assigned to newObj is

const newObj: {
    foo: number;
}

We've also tried setting the object type manually like this:

interface NewObjType {
  foo:number,
  bar:number
}
const obj = { foo: 1 };
const newObj = set('bar')(2)<NewObjType>(obj);

Which assigns the correct type to newObj, but we're not sure if the path or value matches the expected type. Anyone knows a solution to this?

0 Answers
Related