-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
chore: followup to jest-mock TS migration #7850
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -911,7 +911,7 @@ class ModuleMockerClass { | |
return metadata; | ||
} | ||
|
||
isMockFunction(fn: any): boolean { | ||
isMockFunction<T, Y extends unknown[]>(fn: any): fn is Mock<T, Y> { | ||
return !!fn && fn._isMockFunction === true; | ||
} | ||
|
||
|
@@ -943,7 +943,7 @@ class ModuleMockerClass { | |
? SpyInstance<ReturnType<T[M]>, ArgsType<T[M]>> | ||
: never; | ||
|
||
spyOn<T extends {}, M extends keyof T>( | ||
spyOn<T extends {}, M extends NonFunctionPropertyNames<T>>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. heh, not this is not entirely true because this generic I don't really understand why a function even needs type definitions when it's overloaded like this. Generated types are only for the definitions as well, so that seems really counterintuitive, not to mention it causes headaches on "how to fit all the typings in this def and make TS happy, even though it may be a lie" 😅 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. heh, yeah. we might want to add actual tests on the types at some point (e.g. https://www.npmjs.com/package/tsd-check or https://www.npmjs.com/package/dts-jest) |
||
object: T, | ||
methodName: M, | ||
accessType?: 'get' | 'set', | ||
|
@@ -985,7 +985,7 @@ class ModuleMockerClass { | |
return object[methodName]; | ||
} | ||
|
||
private _spyOnProperty<T extends {}, M extends keyof T>( | ||
private _spyOnProperty<T extends {}, M extends NonFunctionPropertyNames<T>>( | ||
obj: T, | ||
propertyName: M, | ||
accessType: 'get' | 'set' = 'get', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this makes sense or not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Y is optional and
unknown[]
by default, so you can omit that. Docs say that type gruard performs runtime check, but I don't see a change in the build output. Anyway, it makes sense to meThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the built output is the same, this is just us telling the type system that if the function returns
true
what the type is. Basically atypeof