react, react-test-renderer: Update React types for 16.9.0#37426
Conversation
| */ | ||
| // the "void | undefined" is here to forbid any sneaky return values | ||
| // tslint:disable-next-line: void-return | ||
| export function act(callback: () => Promise<void | undefined>): Promise<undefined>; |
There was a problem hiding this comment.
() => Promise<void> would essentially accept Promise<any>, so it's |ed with undefined to enforce no values are returned. Just Promise<undefined> would reject void functions.
There was a problem hiding this comment.
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)
if (somethingThatMakesMeReturnEarly) {
return doSomethingElse()
}There was a problem hiding this comment.
What's the problem with Promise<any>?
I'm incurring into an error when trying to do something like this:
await act(() =>
expect(result.current.validate()).rejects.toEqual({ a: "error" })
);expect(somePromise).rejects.toEqual() will return the same type returned by somePromise. Test passes, but TypeScript is complaining: Type 'Promise<SomePromiseReturn>' is not assignable to type 'void'.
There was a problem hiding this comment.
@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 just void. It's not obvious anyway that expect.rejects returns a promise which makes this act harder to read than necessary.
| /** | ||
| * Not implemented yet, requires unstable_ConcurrentMode | ||
| */ | ||
| // maxDuration?: number; |
There was a problem hiding this comment.
Both this and unstable_ConcurrentMode were removed. unstable_ConcurrentMode was never added to the types anyway.
| } | ||
|
|
||
| const unstable_Profiler: ExoticComponent<ProfilerProps>; | ||
| const Profiler: ExoticComponent<ProfilerProps>; |
| playsInline?: boolean; | ||
| poster?: string; | ||
| width?: number | string; | ||
| disablePictureInPicture?: boolean; |
There was a problem hiding this comment.
| 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.
Sometimes it's "async" | "auto" | "sync" | undefined, sometimes it's "auto" | "async" | "sync" | undefined. Not sure why. It doesn't matter for type checking, but dtslint cares about it.
|
@Jessidhia Thank you for submitting this PR! 🔔 @johnnyreilly @bbenezech @pzavolinsky @digiguru @ericanderson @DovydasNavickas @onigoetz @theruther4d @guilhermehubner @ferdaber @jrakotoharisoa @pascaloliv @Hotell @franklixuefei @saranshkataria @lukyth @eps1lon @arvitaly @lochbrunner @jgoz - please review this PR in the next few days. Be sure to explicitly select If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead. |
|
Since you're a listed owner and the build passed, this PR is fast-tracked. A maintainer will merge shortly. If it shouldn't be merged yet, please leave a comment saying so and we'll wait. Thank you for your contribution to DefinitelyTyped! |
|
I thought of adding this as an additional file inside the project, but I couldn't find any way that works well. dtslint doesn't like module augmentation within the same module, and when I get something that does appear to work with // Definitions for unstable APIs present in React
// Current to 16.9.0-rc.0
declare namespace React {
//#region unflagged features
export interface UnstableSuspenseListPropsCommon {
// ReactFiberSuspenseComponent:SuspenseListTailMode
// ReactFiberBeginWork:validateTailOptions
tail?: 'collapsed' | 'hidden';
}
export interface UnstableSuspenseListPropsUnordered extends UnstableSuspenseListPropsCommon {
// ReactFiberBeginWork:validateRevealOrder
revealOrder?: 'together';
// ReactFiberBeginWork:validateSuspenseListChildren
children?: ReactNode;
}
export interface UnstableSuspenseListPropsOrdered extends UnstableSuspenseListPropsCommon {
// children are only validated when the revealOrder is either of these values
// ReactFiberBeginWork:validateRevealOrder
// ReactFiberBeginWork:validateSuspenseListChildren
revealOrder: 'forwards' | 'backwards';
// ReactFiberBeginWork:validateSuspenseListChildren
// Array works too but this accepts any Iterable, including Array
children?: Iterable<ReactChild | undefined | null | false> | null | false;
}
export type UnstableSuspenseListProps = UnstableSuspenseListPropsOrdered | UnstableSuspenseListPropsUnordered;
export const unstable_SuspenseList: ExoticComponent<UnstableSuspenseListProps>;
export interface UnstableSuspenseConfig {
timeoutMs: number;
busyDelayMs?: number;
busyMinDurationMs?: number;
}
// https://github.com/facebook/react/pull/15593
export function unstable_withSuspenseConfig(
scope: () => void | undefined,
config?: UnstableSuspenseConfig | null,
): void;
//#endregion
//#region enableFlareAPI
// https://github.com/facebook/react/blob/v16.9.0-rc.0/packages/shared/forks/ReactFeatureFlags.www.js#L73
// NOTE: the actual internal implementations are on the reconciler,
// so this uses the react-dom reconciler as the reference right now.
// only HostComponent (i.e. DOM nodes) can receive listeners
// TODO: requires declaring react-events package
//#endregion
//#region enableFundamentalAPI
// https://github.com/facebook/react/blob/v16.9.0-rc.0/packages/shared/forks/ReactFeatureFlags.www.js#L75
// https://github.com/facebook/react/pull/16049
// "Note: this is a completely private API for internal experimentation use only",
// and its flag is turned off, so not defined.
//#endregion
//#region enableJSXTransformAPI
// https://github.com/facebook/react/blob/v16.9.0-rc.0/packages/shared/forks/ReactFeatureFlags.www.js#L77
// implementation of https://github.com/reactjs/rfcs/pull/107
export function jsx<C extends ElementType>(
type: C,
config: JSX.LibraryManagedAttributes<C, ComponentPropsWithRef<C>>,
maybeKey?: Key,
): ReactElement<ComponentPropsWithRef<C>, C>;
// TODO: implement the difference between jsx and jsxs
// (there isn't one, really, but jsxs is more optimized when multiple children are passed)
export { jsx as jsxs };
/**
* NOTE: undefined in production builds
*/
export function jsxDEV<C extends ElementType>(
type: C,
config: JSX.LibraryManagedAttributes<C, ComponentPropsWithRef<C>>,
maybeKey?: Key,
source?: { fileName: string; lineNumber: number },
self?: C,
): ReactElement<ComponentPropsWithRef<C>, C>;
//#endregion
//#region enableSuspenseCallback
// https://github.com/facebook/react/blob/v16.9.0-rc.0/packages/shared/forks/ReactFeatureFlags.www.js#L81
export interface SuspenseProps {
callback?(queuedUpdates: ReadonlySet<PromiseLike<any>>): void;
}
//#endregion
} |
|
It looks like |
|
I restarted the build for now, but I probably need to ship the make-npm-install-single-threaded fix from dtslint-runner to types-publisher as well. |
|
16.9.0 is released so releasing this 🎉 |
|
I just published |
|
I just published |
For now I only quickly went through the changes in the changelog at react/react#16254. Will check for more things on the entry points later.
Please fill in this template.
npm test.)npm run lint package-name(ortscif notslint.jsonis present).Select one of these and delete the others:
If changing an existing definition:
tslint.jsoncontaining{ "extends": "dtslint/dt.json" }.