-
-
Notifications
You must be signed in to change notification settings - Fork 44
Conversation
* fix(typescript): fix query typings * fix(typescript): remove NativeTestInstance from function argument in Query interface * chore: remove unnecessary code
Codecov Report
@@ Coverage Diff @@
## master #32 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 20 20
Lines 262 262
Branches 65 65
=====================================
Hits 262 262 Continue to review full report at Codecov.
|
@bcarroll22 I'm sorry for the late reply. I would love to get feedback on this! |
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.
This is awesome, thanks for tackling this! If you could please address those few things I mentioned we’ll get this merged ASAP!
@@ -10,12 +10,12 @@ import { getQueriesForElement, BoundFunction } from './get-queries-for-element'; | |||
declare const within: typeof getQueriesForElement; | |||
|
|||
interface Query extends Function { | |||
(testRenderer: ReactTestRenderer | NativeTestInstance, ...args: any[]): | |||
(testRenderer: ReactTestRenderer, ...args: any[]): |
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 think this may be backwards. A query only takes a NativeTestInstance, never a ReactTestRenderer.
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.
Oh I just thought testRenderer should be ReactTestRenderer
by seeing these changes.
manakuro@d8c3b30#diff-0da64c26f363af99c40bbae0dc3fb0bfR8
Should it be replaced with NativeTestInstance
in typings/queries.d.ts
like this ?
export type QueryByBoundProp = (
testRenderer: NativeTestInstance,
id: Matcher,
options?: MatcherOptions,
) => NativeTestInstance | null;
...
and Query just takes NativeTestInstance
?
interface Query extends Function {
(testRenderer: NativeTestInstance, ...args: any[]):
| Error
| Promise<NativeTestInstance[]>
| Promise<NativeTestInstance>
| NativeTestInstance[]
| NativeTestInstance
| null;
}
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.
Yep this is right. And to make it more clear, we might want to change the name of the argument from testRenderer
as a part of this as well 👍
@@ -4,12 +4,12 @@ import { Matcher, MatcherOptions } from './matches'; | |||
|
|||
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; | |||
|
|||
export interface SelectorMatcherOptions extends MatcherOptions { | |||
export type SelectorMatcherOptions = Omit<MatcherOptions, 'selector'> & { |
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.
Can you help me understand what this one does?
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.
The previous one tried to extend MatcherOptions
and override selector
property but TypeScript cannot override interface property. So to do that, you can use Omit
to exclude selector
and extend it again.
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.
Got it, thanks 👍
|
||
type ReactTestInstance = { | ||
getProp: (string) => NativeTestInstance; | ||
getProp: (str: string) => NativeTestInstance; |
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.
Can you make this something more descriptive of what this is? Like name
possibly?
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.
Yes. This is just a syntax error. You need to use type and name together.
https://www.typescriptlang.org/docs/handbook/functions.html#writing-the-function-type
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.
Yep, can we make the name of the argument name
so that it’s clear from the typings what getProp
is looking for?
This should also replace |
@mAAdhaTTah in case this PR doesn’t address your concern or you need it faster, I’ll review one from you today that fixes it if you’d like? |
@bcarroll22 PR'd as #34 but we're going to need both of these PRs to get TS to stop complaining. |
@manakuro any ideas when we can wrap this one up? |
I'm going to go ahead and get this merged and make the few changes so that this change is working for others as well. Thanks for the help! @allcontributors please add @manakuro for code. |
I've put up a pull request to add @manakuro! 🎉 |
🎉 This PR is included in version 4.0.3 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
What:
Fix Query typings.
Why:
Typings error occurred because of incompatible with Query interface as noted in #30.
How:
NativeTestInstance
type for returning Query interface.NativeTestInstance
type fromtestRenderer
argument in Query interface.ReactTestInstance.getProps
type.Checklist:
docs site
Results: