Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Fix #8: Generated type of expect #9

Merged
merged 1 commit into from
Feb 4, 2022
Merged

Conversation

FTWinston
Copy link
Contributor

Declaring the type explicitly seems to fix the generated type definitions.

With this change, index.d.ts generates as:

import { default as expectPatched } from '@storybook/expect';
import * as mock from 'jest-mock';
export declare const jest: typeof mock;
export declare const expect: typeof expectPatched;

instead of as

import * as mock from 'jest-mock';
export declare const jest: typeof mock;
export declare const expect: import("expect/build/types").Expect<import("expect/build/types").MatcherState>;

This prevents the typescript-eslint errors reported on #8.

Copy link
Member

@yannbf yannbf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @FTWinston thanks a lot for your contribution! I think this is great but still there is a problem with the package, which is the fact that @storybook/expect, although it include types, it actually just re-exports types from expect, but it does not have it as a peerDependency. People who don't have expect in their projects at all will still have typing issues. But anyways, this PR already provides a great fix for those who do have expect!

@FTWinston
Copy link
Contributor Author

Hmm, so should @storybook/jest list expect as a peer dependency (too), or should that be left to @storybook/expect?

@yannbf
Copy link
Member

yannbf commented Jan 27, 2022

Hmm, so should @storybook/jest list expect as a peer dependency (too), or should that be left to @storybook/expect?

Great question! Expect is bundled in @storybook/expect, but the types are lost. We need to figure out a way to copy and re-export the types from that package so there's no need to install expect only for the types!

@yannbf yannbf added the patch Increment the patch version when merged label Feb 4, 2022
@yannbf yannbf merged commit 315ae0f into storybookjs:main Feb 4, 2022
@github-actions
Copy link

github-actions bot commented Feb 4, 2022

🚀 PR was released in v0.0.6 🚀

@github-actions github-actions bot added the released This issue/pull request has been released. label Feb 4, 2022
@FTWinston FTWinston deleted the types branch February 4, 2022 13:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
patch Increment the patch version when merged released This issue/pull request has been released.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants