Skip to content

fix: correct function type for spyon an optional function #19240

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

li-yechao
Copy link

@li-yechao li-yechao commented Apr 24, 2025

What does this PR do?

Mock type is incorrect when spyOn a nullable function, like this:

  const test: {
    optionalMethod?: (input: { question: string }) => { answer: string };
  } = {
    optionalMethod: (input) => ({ answer: `Aswer to ${input.question}` }),
  };

  const a = spyOn(test, "optionalMethod");

typeof a is Mock<never>

How did you verify your code works?

@RiskyMH RiskyMH added the types An issue with TypeScript types label Apr 25, 2025
@alii alii self-requested a review April 25, 2025 04:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
types An issue with TypeScript types
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants