Skip to content

Commit

Permalink
Fix bug with meta not working well as generic parameter for StoryObj
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperpeulen committed Dec 8, 2022
1 parent f5aa7bd commit 113cfc9
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 39 deletions.
2 changes: 1 addition & 1 deletion code/addons/links/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"dependencies": {
"@storybook/client-logger": "7.0.0-beta.0",
"@storybook/core-events": "7.0.0-beta.0",
"@storybook/csf": "next",
"@storybook/csf": "0.0.2--canary.60.011a95e.0",
"@storybook/manager-api": "7.0.0-beta.0",
"@storybook/preview-api": "7.0.0-beta.0",
"@storybook/router": "7.0.0-beta.0",
Expand Down
2 changes: 1 addition & 1 deletion code/addons/storyshots/storyshots-puppeteer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"dependencies": {
"@axe-core/puppeteer": "^4.2.0",
"@storybook/csf": "next",
"@storybook/csf": "0.0.2--canary.60.011a95e.0",
"@storybook/node-logger": "7.0.0-beta.0",
"@storybook/types": "7.0.0-beta.0",
"@types/jest-image-snapshot": "^5.1.0",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/codemod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"dependencies": {
"@babel/types": "^7.20.2",
"@storybook/csf": "next",
"@storybook/csf": "0.0.2--canary.60.011a95e.0",
"@storybook/csf-tools": "7.0.0-beta.0",
"@storybook/node-logger": "7.0.0-beta.0",
"@storybook/types": "7.0.0-beta.0",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/core-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@storybook/builder-manager": "7.0.0-beta.0",
"@storybook/core-common": "7.0.0-beta.0",
"@storybook/core-events": "7.0.0-beta.0",
"@storybook/csf": "next",
"@storybook/csf": "0.0.2--canary.60.011a95e.0",
"@storybook/csf-tools": "7.0.0-beta.0",
"@storybook/docs-mdx": "next",
"@storybook/node-logger": "7.0.0-beta.0",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/csf-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"dependencies": {
"@babel/types": "^7.20.2",
"@storybook/csf": "next",
"@storybook/csf": "0.0.2--canary.60.011a95e.0",
"@storybook/types": "7.0.0-beta.0",
"fs-extra": "^9.0.1",
"ts-dedent": "^2.0.0"
Expand Down
2 changes: 1 addition & 1 deletion code/lib/manager-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@storybook/channels": "7.0.0-beta.0",
"@storybook/client-logger": "7.0.0-beta.0",
"@storybook/core-events": "7.0.0-beta.0",
"@storybook/csf": "next",
"@storybook/csf": "0.0.2--canary.60.011a95e.0",
"@storybook/router": "7.0.0-beta.0",
"@storybook/theming": "7.0.0-beta.0",
"@storybook/types": "7.0.0-beta.0",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/preview-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"@storybook/channels": "7.0.0-beta.0",
"@storybook/client-logger": "7.0.0-beta.0",
"@storybook/core-events": "7.0.0-beta.0",
"@storybook/csf": "next",
"@storybook/csf": "0.0.2--canary.60.011a95e.0",
"@storybook/types": "7.0.0-beta.0",
"@types/qs": "^6.9.5",
"dequal": "^2.0.2",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/source-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {
"@storybook/csf": "next",
"@storybook/csf": "0.0.2--canary.60.011a95e.0",
"@storybook/types": "7.0.0-beta.0",
"estraverse": "^5.2.0",
"lodash": "^4.17.21",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"file-system-cache": "^2.0.0"
},
"devDependencies": {
"@storybook/csf": "next",
"@storybook/csf": "0.0.2--canary.60.011a95e.0",
"@types/node": "^16.0.0",
"typescript": "~4.9.3"
},
Expand Down
2 changes: 1 addition & 1 deletion code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
"@storybook/core-events": "workspace:*",
"@storybook/core-server": "workspace:*",
"@storybook/core-webpack": "workspace:*",
"@storybook/csf": "next",
"@storybook/csf": "0.0.2--canary.60.011a95e.0",
"@storybook/csf-plugin": "workspace:*",
"@storybook/csf-tools": "workspace:*",
"@storybook/docs-tools": "workspace:*",
Expand Down
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>();
});
2 changes: 1 addition & 1 deletion code/ui/blocks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@storybook/client-logger": "7.0.0-beta.0",
"@storybook/components": "7.0.0-beta.0",
"@storybook/core-events": "7.0.0-beta.0",
"@storybook/csf": "next",
"@storybook/csf": "0.0.2--canary.60.011a95e.0",
"@storybook/docs-tools": "7.0.0-beta.0",
"@storybook/manager-api": "7.0.0-beta.0",
"@storybook/preview-api": "7.0.0-beta.0",
Expand Down
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.CLOSED,
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.CLOSED,
},
};

Expand Down
2 changes: 1 addition & 1 deletion code/ui/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
},
"dependencies": {
"@storybook/client-logger": "7.0.0-beta.0",
"@storybook/csf": "next",
"@storybook/csf": "0.0.2--canary.60.011a95e.0",
"@storybook/theming": "7.0.0-beta.0",
"@storybook/types": "7.0.0-beta.0",
"memoizerific": "^1.11.3",
Expand Down
44 changes: 22 additions & 22 deletions code/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5385,7 +5385,7 @@ __metadata:
dependencies:
"@storybook/client-logger": 7.0.0-beta.0
"@storybook/core-events": 7.0.0-beta.0
"@storybook/csf": next
"@storybook/csf": 0.0.2--canary.60.011a95e.0
"@storybook/manager-api": 7.0.0-beta.0
"@storybook/preview-api": 7.0.0-beta.0
"@storybook/router": 7.0.0-beta.0
Expand Down Expand Up @@ -5457,7 +5457,7 @@ __metadata:
resolution: "@storybook/addon-storyshots-puppeteer@workspace:addons/storyshots/storyshots-puppeteer"
dependencies:
"@axe-core/puppeteer": ^4.2.0
"@storybook/csf": next
"@storybook/csf": 0.0.2--canary.60.011a95e.0
"@storybook/node-logger": 7.0.0-beta.0
"@storybook/types": 7.0.0-beta.0
"@types/jest-image-snapshot": ^5.1.0
Expand Down Expand Up @@ -5819,7 +5819,7 @@ __metadata:
"@storybook/client-logger": 7.0.0-beta.0
"@storybook/components": 7.0.0-beta.0
"@storybook/core-events": 7.0.0-beta.0
"@storybook/csf": next
"@storybook/csf": 0.0.2--canary.60.011a95e.0
"@storybook/docs-tools": 7.0.0-beta.0
"@storybook/manager-api": 7.0.0-beta.0
"@storybook/preview-api": 7.0.0-beta.0
Expand Down Expand Up @@ -6098,7 +6098,7 @@ __metadata:
resolution: "@storybook/codemod@workspace:lib/codemod"
dependencies:
"@babel/types": ^7.20.2
"@storybook/csf": next
"@storybook/csf": 0.0.2--canary.60.011a95e.0
"@storybook/csf-tools": 7.0.0-beta.0
"@storybook/node-logger": 7.0.0-beta.0
"@storybook/types": 7.0.0-beta.0
Expand All @@ -6121,7 +6121,7 @@ __metadata:
dependencies:
"@popperjs/core": ^2.6.0
"@storybook/client-logger": 7.0.0-beta.0
"@storybook/csf": next
"@storybook/csf": 0.0.2--canary.60.011a95e.0
"@storybook/theming": 7.0.0-beta.0
"@storybook/types": 7.0.0-beta.0
"@types/overlayscrollbars": ^1.12.0
Expand Down Expand Up @@ -6219,7 +6219,7 @@ __metadata:
"@storybook/builder-webpack5": 7.0.0-beta.0
"@storybook/core-common": 7.0.0-beta.0
"@storybook/core-events": 7.0.0-beta.0
"@storybook/csf": next
"@storybook/csf": 0.0.2--canary.60.011a95e.0
"@storybook/csf-tools": 7.0.0-beta.0
"@storybook/docs-mdx": next
"@storybook/node-logger": 7.0.0-beta.0
Expand Down Expand Up @@ -6306,7 +6306,7 @@ __metadata:
"@babel/parser": ^7.20.3
"@babel/traverse": ^7.20.1
"@babel/types": ^7.20.2
"@storybook/csf": next
"@storybook/csf": 0.0.2--canary.60.011a95e.0
"@storybook/types": 7.0.0-beta.0
"@types/fs-extra": ^9.0.6
fs-extra: ^9.0.1
Expand All @@ -6325,23 +6325,23 @@ __metadata:
languageName: node
linkType: hard

"@storybook/csf@npm:^0.0.1":
version: 0.0.1
resolution: "@storybook/csf@npm:0.0.1"
"@storybook/csf@npm:0.0.2--canary.60.011a95e.0":
version: 0.0.2--canary.60.011a95e.0
resolution: "@storybook/csf@npm:0.0.2--canary.60.011a95e.0"
dependencies:
expect-type: ^0.14.2
lodash: ^4.17.15
checksum: 7b0f75763415f9147692a460b44417ee56ea9639433716a1fd4d1df4c8b0221cbc71b8da0fbed4dcecb3ccd6c7ed64be39f5c255c713539a6088a1d6488aaa24
type-fest: ^2.19.0
checksum: ee63482c11dab2de13fcef1916fec235130d02446642da087907e04b9e8672169f0b11efa40bf3ca699d497a53882b4928349163b77ca2161546f16d6f987484
languageName: node
linkType: hard

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

Expand Down Expand Up @@ -6567,7 +6567,7 @@ __metadata:
"@storybook/channels": 7.0.0-beta.0
"@storybook/client-logger": 7.0.0-beta.0
"@storybook/core-events": 7.0.0-beta.0
"@storybook/csf": next
"@storybook/csf": 0.0.2--canary.60.011a95e.0
"@storybook/router": 7.0.0-beta.0
"@storybook/theming": 7.0.0-beta.0
"@storybook/types": 7.0.0-beta.0
Expand Down Expand Up @@ -6920,7 +6920,7 @@ __metadata:
"@storybook/client-logger": 7.0.0-beta.0
"@storybook/core-common": 7.0.0-beta.0
"@storybook/core-events": 7.0.0-beta.0
"@storybook/csf": next
"@storybook/csf": 0.0.2--canary.60.011a95e.0
"@storybook/types": 7.0.0-beta.0
"@types/qs": ^6.9.5
ansi-to-html: ^0.6.11
Expand Down Expand Up @@ -7127,7 +7127,7 @@ __metadata:
"@storybook/core-events": "workspace:*"
"@storybook/core-server": "workspace:*"
"@storybook/core-webpack": "workspace:*"
"@storybook/csf": next
"@storybook/csf": 0.0.2--canary.60.011a95e.0
"@storybook/csf-plugin": "workspace:*"
"@storybook/csf-tools": "workspace:*"
"@storybook/docs-tools": "workspace:*"
Expand Down Expand Up @@ -7405,7 +7405,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@storybook/source-loader@workspace:lib/source-loader"
dependencies:
"@storybook/csf": next
"@storybook/csf": 0.0.2--canary.60.011a95e.0
"@storybook/types": 7.0.0-beta.0
estraverse: ^5.2.0
jest-specific-snapshot: ^7.0.0
Expand Down Expand Up @@ -7587,7 +7587,7 @@ __metadata:
dependencies:
"@babel/core": ^7.12.10
"@storybook/channels": 7.0.0-beta.0
"@storybook/csf": next
"@storybook/csf": 0.0.2--canary.60.011a95e.0
"@types/babel__core": ^7.0.0
"@types/express": ^4.7.0
"@types/node": ^16.0.0
Expand Down

0 comments on commit 113cfc9

Please sign in to comment.