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

Suggestion for more accurate types for nested objects #884

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

NickBolles
Copy link

@NickBolles NickBolles commented Dec 16, 2024

fixes #885

export class MyClass {
  foo = {
    bar: () => {
      return 'foo.bar';
    },
  };
}

test('foo.bar', () => {
  const myMock = createMock<MyClass>();

  myMock.foo.bar.mockResolvedValue('foo.bar');
});
image

Based off the createMock source this nested object should also be a mock. Updating the typings as suggested fix this.

There are very likely other spots that need to be fixed too, I just looked at this specific error for now, if this is a good change I can look at the rest and add them to the PR.

@NickBolles NickBolles changed the title Suggestion for more accurate types Suggestion for more accurate types for nested objects Dec 16, 2024
@underfisk
Copy link
Contributor

@NickBolles Are you able to add test coverage to fully expose this case? I'm trying to see which more scenarios this would capture and whether it may introduce hotspots to the typescript compiler

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

Successfully merging this pull request may close these issues.

Nested objects aren't typed as DeepMocked
2 participants