Skip to content
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

Typescript: Fix bug with meta not working well as generic parameter for StoryObj #20165

Merged
merged 1 commit into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions code/renderers/react/src/public-types.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,31 @@ describe('Story args can be inferred', () => {
expectTypeOf(Basic).toEqualTypeOf<Expected>();
});
});

test('StoryObj<typeof meta> is allowed when meta is upcasted to Meta<Props>', () => {
expectTypeOf<StoryObj<Meta<ButtonProps>>>().toEqualTypeOf<
ReactStory<
ButtonProps & { children?: ReactNode },
Partial<ButtonProps & { children?: ReactNode }>
>
>();
});

test('StoryObj<typeof meta> is allowed when meta is upcasted to Meta<typeof Cmp>', () => {
expectTypeOf<StoryObj<Meta<typeof Button>>>().toEqualTypeOf<
ReactStory<
ButtonProps & { children?: ReactNode },
Partial<ButtonProps & { children?: ReactNode }>
>
>();
});

test('StoryObj<typeof meta> is allowed when all arguments are optional', () => {
expectTypeOf<StoryObj<Meta<{ label?: string }>>>().toEqualTypeOf<
ReactStory<{ label?: string; children?: ReactNode }, { label?: string; children?: ReactNode }>
>();
});

test('Meta can be used without generic', () => {
expectTypeOf({ component: Button }).toMatchTypeOf<Meta>();
});
10 changes: 5 additions & 5 deletions code/ui/blocks/src/blocks/Canvas.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import type { Meta, StoryObj } from '@storybook/react';
import { Canvas } from './Canvas';
import { Canvas, SourceState } from './Canvas';
import { Story as StoryComponent } from './Story';
import * as BooleanStories from '../controls/Boolean.stories';

Expand All @@ -25,20 +25,20 @@ export const BasicStory: Story = {};

export const WithSourceOpen: Story = {
args: {
withSource: 'open',
withSource: SourceState.OPEN,
},
};
export const WithSourceClosed: Story = {
args: {
withSource: 'closed',
withSource: SourceState.CLOSED,
},
};

// TODO: what is the purpose of mdxSource exactly?
export const WithMdxSource: Story = {
name: 'With MDX Source',
args: {
withSource: 'open',
withSource: SourceState.OPEN,
mdxSource: `const thisIsCustomSource = true;
if (isSyntaxHighlighted) {
console.log('syntax highlighting is working');
Expand All @@ -48,7 +48,7 @@ if (isSyntaxHighlighted) {

export const WithoutSource: Story = {
args: {
withSource: 'none',
withSource: SourceState.NONE,
},
};

Expand Down
6 changes: 3 additions & 3 deletions code/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6335,13 +6335,13 @@ __metadata:
linkType: hard

"@storybook/csf@npm:next":
version: 0.0.2-next.7
resolution: "@storybook/csf@npm:0.0.2-next.7"
version: 0.0.2-next.8
resolution: "@storybook/csf@npm:0.0.2-next.8"
dependencies:
expect-type: ^0.14.2
lodash: ^4.17.15
type-fest: ^2.19.0
checksum: 3920626fdd6dc4875ba95ae46fa0776051f544a479029ee7d561b87602511010161750a42b0d5e1371ec336b47262e1098524c834805ca686d9bc2de5cae0e4e
checksum: 86f5599c030b87cbab6fa5e4b4a9ef1aeed5e838b993b2bae5f0fc50d79ae80d5cfbf2590a05bae0a95068ef77eec88d8c102072d63c77745afe74f91cfa03a3
languageName: node
linkType: hard

Expand Down