[Bug]: expect
matchers from @storybook/test
are unexpectedly not generic
#30539
Labels
expect
matchers from @storybook/test
are unexpectedly not generic
#30539
Describe the bug
Hello, we noticed this issue while migrating from v7 to v8. Some of
expect
matchers from@storybook/jest
were generic (accepts type arguments), but those from@storybook/test
are not.In short, we're seeing below TypeScript error:
To compare with
expect
from vitest:I think it's good for
@storybook/test
'sexpect
function to behave similarly to the vitest one as much as possible, hence reporting this as a bug.At least, the current behavior is very confusing because when user uses TypeScript's Peek Definition feature on the erroring
toMatchObject
call, it guides user to the signature that does have a type parameter. (You can see the behavior in the TypeScript Playground linked below.)I think the culprit for the bug is in below code from
@storybook/test
:Promisify<Fn>
removes type parameters fromFn
.Unfortunately I don't have a specific fix to suggest, reporting this anyway.
Reproduction link
https://www.typescriptlang.org/play/?module=1&ts=5.7.2#code/JYWwDg9gTgLgBAbzgUwB5mQY3gXzgMyghDgCIABAZxmgE8AjCCAawHoZlrSBuAKF+AA7DlHwBDTMjgAxJgHl6AK0S84BJgC44ggK4h6yKHxz9MEQdTgQlW2RAXKAvCrX5NcAIwAmAMwAaXhNeNAxsAApvHwBKADoaAFkxGEwACwcsGAAeOwcAPjDrRSi+VlY1corKqoqAPTr63lK4ABVaDABlTChgMHgAUSgiKC0+9AzkABM4AAY4GDapMSgAcz1kYUo-OHodeGWIeA8YoA
Reproduction steps
Open the TypeScript Playground link above and wait for a while. Then you'll see a TypeScript error.
System
Additional context
The list of
expect
methods affected by this issue: toEqual, toStrictEqual, toMatchObject, toContain, toContainEqual, toBeInstanceOf, toHaveProperty, toHaveBeenCalledWith, toBeCalledWith, toHaveBeenNthCalledWith, nthCalledWith, toHaveBeenLastCalledWith, lastCalledWith, toReturnWith, tohaveReturnedWith, lastReturnedWith, toHaveNthReturnedWith, nthReturnedWithThe text was updated successfully, but these errors were encountered: