Skip to content

Commit

Permalink
Merge pull request #21833 from storybookjs/kasper/fix-strict-args-dec…
Browse files Browse the repository at this point in the history
…orator-with-interface

TS: Make sure components with interfaces or no props don't raise decorator assignability issues
  • Loading branch information
kasperpeulen authored Mar 31, 2023
2 parents 2cc1d36 + a08ffc7 commit 9682f7c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
46 changes: 46 additions & 0 deletions code/renderers/react/src/public-types.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,49 @@ test('StoryObj<typeof meta> is allowed when all arguments are optional', () => {
test('Meta can be used without generic', () => {
expectTypeOf({ component: Button }).toMatchTypeOf<Meta>();
});

test('Props can be defined as interfaces, issue #21768', () => {
interface Props {
label: string;
}

const Component = ({ label }: Props) => <>{label}</>;

const withDecorator: Decorator = (Story) => (
<>
<Story />
</>
);

const meta = {
component: Component,
args: {
label: 'label',
},
decorators: [withDecorator],
} satisfies Meta<Props>;

const Basic: StoryObj<typeof meta> = {};

type Expected = ReactStory<Props, SetOptional<Props, 'label'>>;
expectTypeOf(Basic).toEqualTypeOf<Expected>();
});

test('Components without Props can be used, issue #21768', () => {
const Component = () => <>Foo</>;
const withDecorator: Decorator = (Story) => (
<>
<Story />
</>
);

const meta = {
component: Component,
decorators: [withDecorator],
} satisfies Meta<typeof Component>;

const Basic: StoryObj<typeof meta> = {};

type Expected = ReactStory<{}, {}>;
expectTypeOf(Basic).toEqualTypeOf<Expected>();
});
6 changes: 3 additions & 3 deletions code/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6176,11 +6176,11 @@ __metadata:
linkType: hard

"@storybook/csf@npm:next":
version: 0.0.2-next.10
resolution: "@storybook/csf@npm:0.0.2-next.10"
version: 0.0.2-next.11
resolution: "@storybook/csf@npm:0.0.2-next.11"
dependencies:
type-fest: ^2.19.0
checksum: a46deb02d9899b1d85e8fed3bfcdde4368fb8220fd8d78e090046e891241cfa0f294c91687d0ac592c7d8036f1294be8874fab14f11ecabe255659272047c961
checksum: fa4025ff520fcfc6eaf9bb9cabbf11d5c06d6ae7ec91bd8102f8f32505ca9149b305e55cd151789a18c1ddee69fe6997293aeff20dcc8c28b6f09833c98a8831
languageName: node
linkType: hard

Expand Down

0 comments on commit 9682f7c

Please sign in to comment.