React-hooks-testing-library: Type definitions are not up to date

Created on 13 Dec 2019  路  4Comments  路  Source: testing-library/react-hooks-testing-library

  • react-hooks-testing-library version: 3.2.1
  • react-test-renderer version: 16.12.0
  • react version: 16.12.0
  • node version: 12.13.1
  • npm version: 6.12.1

Relevant code or config:

let your = (code, tell) => `the ${story}`

What you did:

Using Typescript:
const { wait } = renderHook(() =>

What happened:

I get this error 'wait' is declared but its value is never read.

Problem description:

type definitions is no up to date

Suggested solution:

Somehow update type definition because the current definition for the v3.2.1 is

// Type definitions for @testing-library/react-hooks 3.1
// Project: https://github.com/testing-library/react-hooks-testing-library
// Definitions by: Michael Peyper <https://github.com/mpeyper>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0

import { ComponentType } from 'react';
export { act } from 'react-test-renderer';

export interface RenderHookOptions<P> {
    initialProps?: P;
    wrapper?: React.ComponentType;
}

export interface HookResult<R> {
    readonly current: R;
    readonly error: Error;
}

export interface RenderHookResult<P, R> {
    readonly result: HookResult<R>;
    readonly waitForNextUpdate: () => Promise<void>;
    readonly unmount: () => boolean;
    readonly rerender: (newProps?: P) => void;
}

/**
 * Renders a test component that will call the provided `callback`, including any hooks it calls, every time it renders.
 */
export function renderHook<P, R>(callback: (props: P) => R, options?: RenderHookOptions<P>): RenderHookResult<P, R>;

/**
 * Unmounts any rendered hooks rendered with `renderHook`, ensuring all effects have been flushed.
 */
export function cleanup(): Promise<void>;
bug good first issue help wanted

Most helpful comment

Hi there. I've added the type information for wait and waitForValueToChange, based on the given signatures from the documentation.

PR: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/41028

All 4 comments

The types have moved to DefinitelyTyped to be maintained by the typescript community.

Please open an issue in that repo and consider making a contribution to update the types. I'll gladly review PRs to update them.

I'm happy to keep this open until they are brought up to date.

Hi there. I've added the type information for wait and waitForValueToChange, based on the given signatures from the documentation.

PR: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/41028

The branch is merged on DT, you can close this 馃檪

Thank you @sarahdayan. If you want to, you can open a PR to add yourself as a contributor. I'm not sure which type best suits type definitions, perhaps platform or plugin, but feel free to choose whatever you think is most appropriate.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DaveStein picture DaveStein  路  7Comments

alexkrolick picture alexkrolick  路  5Comments

mtinner picture mtinner  路  3Comments

SachinSaggezza picture SachinSaggezza  路  4Comments

ccpu picture ccpu  路  5Comments