Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: cloneDeep does not respect instances of classes (affects compat/omit and compat/pick) #801

Closed
eturino opened this issue Nov 7, 2024 · 4 comments

Comments

@eturino
Copy link

eturino commented Nov 7, 2024

this happens with both cloneDeep and compat.cloneDeep.

It is then affecting other functions like omit.

it('should work with custom classes', () => {
    class CustomTest {
      constructor(public value: number) {}
      myFunc() {
        return `value is ${this.value}`;
      }
    }

    const object = new CustomTest(1);
    const cloned = cloneDeep(object);

    expect(cloned).not.toBe(object);
    expect(cloned).toEqual(object);
    expect(cloned.myFunc()).toBe(object.myFunc()); // <- Error: TypeError: cloned.myFunc is not a function
    expect(cloned.myFunc()).toEqual('value is 1');

    const nested = { customTest: new CustomTest(1) };

    const clonedNested = cloneDeep(nested);

    expect(clonedNested).not.toBe(nested);
    expect(clonedNested).toEqual(nested);
    expect(clonedNested.customTest.myFunc()).toBe(nested.customTest.myFunc());
    expect(clonedNested.customTest.myFunc()).toEqual('value is 1');
  });
@eturino eturino changed the title Bug: cloneDeep does not respect instances of classes Bug: cloneDeep does not respect instances of classes (affects compat/omit and compat/pick) Nov 7, 2024
@D-Sketon
Copy link
Contributor

D-Sketon commented Nov 8, 2024

maybe same as #777, and #794 can solve it

@injae-kim
Copy link

Fix PR: #794

@raon0211
Copy link
Collaborator

This was fixed in es-toolkit v1.27.0 :)

@eturino
Copy link
Author

eturino commented Nov 10, 2024

thanks a lot! congratulations on the impressive cycle time 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants