Skip to content

[Bug]: expect matchers from storybook/test ignores their generic parameter #31563

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

Open
uhyo opened this issue May 25, 2025 · 1 comment
Open

Comments

@uhyo
Copy link

uhyo commented May 25, 2025

Describe the bug

I originally posted this here, but I decided to open a new issue for this.

In short, type definitions for some of the expect matchers from storybook/test are (still) not very good; according to the definition they are generic (accepts a type parameter), but actually the type parameter is meaningless.

Notably, this makes a deviation from vitest matchers which storybook/test's expect is based on.

import { expect as storybookExpect } from "storybook/test"; // [email protected]
import { expect as vitestExpect } from "vitest"; // [email protected]

interface FooObj {
  foo: number;
}

const barObj = {
  bar: "Hello",
};

storybookExpect(123).toMatchObject<FooObj>(barObj); // No error

vitestExpect(123).toMatchObject<FooObj>(barObj);
//                                      ^^^^^^ Error!
// Argument of type '{ bar: string; }' is not assignable to parameter of type 'FooObj'.
//   Property 'foo' is missing in type '{ bar: string; }' but required in type 'FooObj'.

Reproduction link

https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgUwB5mQY3gQwM5x4zQCeARhBANYCi6W8AvnAGZQQhwBERpF1AehjIiXANxwBAuDBIY8ALjgBOAHQAGDQFoomVQBYAUKEixEKetjj44AN2DCidDFeZsO3e45jjJ02fJKAMyqAIwGhsYAdsJQLDiYyHAAYpQA8mQAVoiGcKyUSlEAriBkyFBihoyRmBBRRHBkOFAZ2QC8OXlNUEpcABLIADaDEFwANFWVhrxQ5JS0ljAAFKEATEEAlKrEALI4MJgAFq0MADypEK0AfEvdrRsSUnAAchAoUOxQkV4iMM4MK3WW12+yOJ2w53SWRudyyD0MTzySORKNRaPReQAeticXAaB9oABCBHSACCUAA5iVkDE4BAWDI5EkAORIbpKIhQYBRCkSRjMuDAAhRCC4PB4YAUqI4MiDJLEOBgZo4EDIWJ0hkBFkXVrM1QkpEABXYGFgJDgzJYlAFQrgICFEp5gqijIwFrZzQ5MC5PL5ArIRXgUGQAEcisBgwATZ2u7VQzJ6oA

Reproduction steps

  1. Open the TypeScript Playground link above.
  2. Wait for a while.
  3. See a type error.

System

Storybook Environment Info:

  System:
    OS: Linux 5.15 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish)
    CPU: (16) x64 AMD Ryzen 7 PRO 6850U with Radeon Graphics
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 22.14.0 - ~/.volta/tools/image/node/22.14.0/bin/node
    Yarn: 4.1.1 - ~/.volta/tools/image/yarn/4.1.1/bin/yarn
    npm: 10.9.2 - ~/.volta/tools/image/node/22.14.0/bin/npm <----- active
    pnpm: 8.15.8 - ~/.volta/bin/pnpm
  npmPackages:
    storybook: ^9.0.0-rc.4 => 9.0.0-rc.4

Additional context

I believe the fix in #31395 wasn't perfect. The fix does preserve type parameters from generic matchers, but the function signatures are still broken after Promisify.

Copy link
Contributor

greptile-apps bot commented May 25, 2025

** Disclaimer** This information might be inaccurate, due to it being generated automatically
This appears to be related to the type definitions in @storybook/test package. The issue is in how generic type parameters are handled after the Promisify transformation. Key files to modify: 1. code/lib/test/src/index.ts - Update matcher type definitions 2. code/lib/test/src/types.ts - Fix generic parameter handling Proposed fix: typescript // In types.ts, update the Promisify type to preserve generic parameters: type Promisify<T> = T extends (...args: infer A) => infer R ? (...args: A) => Promise<Awaited<R>> : T extends { [K in keyof T]: (...args: any[]) => any } ? { [K in keyof T]: Promisify<T[K]> } : T; // Update matcher definitions to properly handle generics: interface Matchers<R, T = unknown> { toMatchObject<E extends object>(expected: E): R; // Add other matchers similarly } This should preserve type checking behavior similar to Vitest's implementation.

About Greptile

This response provides a starting point for your research, not a precise solution.

Help us improve! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

Edit Issue Bot Settings · Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant