-
-
Notifications
You must be signed in to change notification settings - Fork 903
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] Incorrect return type output when using jest.mocked #825
Comments
I think this is the gist of the problem. But that's a The TS types bundled with If this worked before, it's only because the [hand-rolled] types defined in
I'm gonna give this a pretty hard "no". Unnecessarily loose types are less helpful and generally considered a code smell. This is also not how v4() is defined in That said, I'll tentatively suggest you could put up a PR if you wanted to propose some alternate incantations for the function overloads in src/v4.ts and I'll take a look. Just be aware my priority is that the types accurately reflect the allowable inputs and outputs of that method, and the code needs to I'll leave this issue open for the time being as it seems other people may be affected by this. For immediate paths forward, I'd suggest one or more of the following:
|
There is a typing cleanup that can be applied to the v4 signature where |
@robbtraister Can you elaborate? |
|
As a workaround, you can use type assertion to bypass the compiler error. Not ideal, obviously.
|
I tried with version 11.0.3 which includes the mentioned PR changes and the typing issue still persists in Jest |
Sorry for any confusion. The fix in 11.0.3 ensures that a string is returned when A possible workaround is to create your own function that wraps import { v4 as uuidV4 } from "uuid";
export function v4(): string {
return uuidV4();
} |
Before you begin...
Description of the problem
Incorrect return type output when using jest.mocked (Uint8Array instead of string)
for example:
jest.mocked(v4).mockReturnValue('str');
in webstorm:
suggesting use of generic to typify buf as it was in @types/uuid:
function v4<T>(options?: Version4Options, buf?: T, offset?: number): T;
instead
function v4(options?: Version4Options, buf?: Uint8Array, offset?: number): Uint8Array;
Recipe for reproducing
1. install uuid 2. setup jest 3. use `jest.mocked(v4).mockReturnValue('str');`
Additional information
No response
Environment
No response
The text was updated successfully, but these errors were encountered: