Skip to content

[@types/lodash] differenceBy types are more strict than code suggests #20741

@legatek

Description

@legatek

If you know how to fix the issue, make a pull request instead.

I have a couple of different classes that use the same semantic property name. Prior to the 4.14.78 release, I could do the following:

class A {
  constructor(myName) {
    this.name = myName;
  }
}

class B {
  constructor(myName, age) {
    this.name = myName;
    this.age = age;
  }
}

let a1 = new A('a1');
let a2 = new A('a2');
let b1 = new B('a1', 30);

let diff = _.differenceBy([a1, a2], [b1], 'name');
// result: [{name: a2}]

Now, the type definition prevents me from doing this because class A and B are not related. It doesn't appear to be a restriction in lodash code itself. Should the type definition be this strict?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions