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
react, react-test-renderer: Update React types for 16.9.0 #37426
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Type definitions for React 16.8 | ||
// Type definitions for React 16.9 | ||
// Project: http://facebook.github.io/react/ | ||
// Definitions by: Asana <https://asana.com> | ||
// AssureSign <http://www.assuresign.com> | ||
|
@@ -349,13 +349,6 @@ declare namespace React { | |
|
||
/** A fallback react tree to show when a Suspense child (like React.lazy) suspends */ | ||
fallback: NonNullable<ReactNode>|null; | ||
|
||
// I tried looking at the code but I have no idea what it does. | ||
// https://github.com/facebook/react/issues/13206#issuecomment-432489986 | ||
/** | ||
* Not implemented yet, requires unstable_ConcurrentMode | ||
*/ | ||
// maxDuration?: number; | ||
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. Both this and unstable_ConcurrentMode were removed. unstable_ConcurrentMode was never added to the types anyway. |
||
} | ||
/** | ||
* This feature is not yet available for server-side rendering. | ||
|
@@ -382,7 +375,7 @@ declare namespace React { | |
onRender: ProfilerOnRenderCallback; | ||
} | ||
|
||
const unstable_Profiler: ExoticComponent<ProfilerProps>; | ||
const Profiler: ExoticComponent<ProfilerProps>; | ||
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. Just renamed. |
||
|
||
// | ||
// Component API | ||
|
@@ -2199,6 +2192,7 @@ declare namespace React { | |
playsInline?: boolean; | ||
poster?: string; | ||
width?: number | string; | ||
disablePictureInPicture?: boolean; | ||
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. https://github.com/facebook/react/pull/15334/files#diff-e19827754462ba391be5fc99b7a3ca09R297 Added as a |
||
} | ||
|
||
// this list is "complete" in that it contains every SVG attribute | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -321,7 +321,7 @@ const ForwardRef3 = React.forwardRef( | |
<ForwardRef3 ref={divFnRef}/>; | ||
<ForwardRef3 ref={divRef}/>; | ||
|
||
const Profiler = React.unstable_Profiler; | ||
const { Profiler } = React; | ||
|
||
// 'id' is missing | ||
<Profiler />; // $ExpectError | ||
|
@@ -357,8 +357,14 @@ const Profiler = React.unstable_Profiler; | |
</Profiler>; | ||
|
||
type ImgProps = React.ComponentProps<'img'>; | ||
// $ExpectType "async" | "auto" | "sync" | undefined | ||
type ImgPropsDecoding = ImgProps['decoding']; | ||
const imgProps: ImgProps = {}; | ||
// the order of the strings in the union seems to vary | ||
// with the typescript version, so test assignment instead | ||
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. Sometimes it's |
||
imgProps.decoding = 'async'; | ||
imgProps.decoding = 'auto'; | ||
imgProps.decoding = 'sync'; | ||
// $ExpectError | ||
imgProps.decoding = 'nonsense'; | ||
type ImgPropsWithRef = React.ComponentPropsWithRef<'img'>; | ||
// $ExpectType ((instance: HTMLImageElement | null) => void) | RefObject<HTMLImageElement> | null | undefined | ||
type ImgPropsWithRefRef = ImgPropsWithRef['ref']; | ||
|
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.
() => Promise<void>
would essentially acceptPromise<any>
, so it's|
ed withundefined
to enforce no values are returned. JustPromise<undefined>
would rejectvoid
functions.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.
Does this affect the test renderer runtime at all if the Promise resolves to a defined value? I think some developers like to combine early returns with an evaluation (still not caring about the return value)
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.
What's the problem with
Promise<any>
?I'm incurring into an error when trying to do something like this:
expect(somePromise).rejects.toEqual()
will return the same type returned bysomePromise
. Test passes, but TypeScript is complaining:Type 'Promise<SomePromiseReturn>' is not assignable to type 'void'.
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.
@diegoazh Please open an issue with the full error message. May also be an issue with the jest typings.
In any case: I would keep it simply an just
await
result.current.validate()
toThrow
and wrap it in a callback that's justvoid
. It's not obvious anyway thatexpect.rejects
returns a promise which makes thisact
harder to read than necessary.