Skip to content

Commit

Permalink
more typesafe CSF3 types for svelte
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperpeulen committed Oct 18, 2022
1 parent 72b3180 commit 7c1b9cc
Show file tree
Hide file tree
Showing 61 changed files with 488 additions and 155 deletions.
2 changes: 1 addition & 1 deletion code/addons/a11y/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"@storybook/client-logger": "7.0.0-alpha.38",
"@storybook/components": "7.0.0-alpha.38",
"@storybook/core-events": "7.0.0-alpha.38",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"@storybook/theming": "7.0.0-alpha.38",
"axe-core": "^4.2.0",
"global": "^4.4.0",
Expand Down
2 changes: 1 addition & 1 deletion code/addons/actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"@storybook/client-logger": "7.0.0-alpha.38",
"@storybook/components": "7.0.0-alpha.38",
"@storybook/core-events": "7.0.0-alpha.38",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"@storybook/theming": "7.0.0-alpha.38",
"dequal": "^2.0.2",
"global": "^4.4.0",
Expand Down
2 changes: 1 addition & 1 deletion code/addons/backgrounds/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"@storybook/client-logger": "7.0.0-alpha.38",
"@storybook/components": "7.0.0-alpha.38",
"@storybook/core-events": "7.0.0-alpha.38",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"@storybook/theming": "7.0.0-alpha.38",
"global": "^4.4.0",
"memoizerific": "^1.11.3",
Expand Down
2 changes: 1 addition & 1 deletion code/addons/controls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"@storybook/client-logger": "7.0.0-alpha.38",
"@storybook/components": "7.0.0-alpha.38",
"@storybook/core-common": "7.0.0-alpha.38",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"@storybook/node-logger": "7.0.0-alpha.38",
"@storybook/store": "7.0.0-alpha.38",
"@storybook/theming": "7.0.0-alpha.38",
Expand Down
2 changes: 1 addition & 1 deletion code/addons/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@storybook/components": "7.0.0-alpha.38",
"@storybook/core-common": "7.0.0-alpha.38",
"@storybook/core-events": "7.0.0-alpha.38",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"@storybook/csf-tools": "7.0.0-alpha.38",
"@storybook/docs-tools": "7.0.0-alpha.38",
"@storybook/mdx1-csf": "0.0.5-canary.13.9ce928a.0",
Expand Down
2 changes: 1 addition & 1 deletion code/addons/interactions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@storybook/components": "7.0.0-alpha.38",
"@storybook/core-common": "7.0.0-alpha.38",
"@storybook/core-events": "7.0.0-alpha.38",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"@storybook/instrumenter": "7.0.0-alpha.38",
"@storybook/theming": "7.0.0-alpha.38",
"global": "^4.4.0",
Expand Down
2 changes: 1 addition & 1 deletion code/addons/links/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"@storybook/addons": "7.0.0-alpha.38",
"@storybook/client-logger": "7.0.0-alpha.38",
"@storybook/core-events": "7.0.0-alpha.38",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"@storybook/router": "7.0.0-alpha.38",
"global": "^4.4.0",
"prop-types": "^15.7.2",
Expand Down
2 changes: 1 addition & 1 deletion code/addons/measure/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"@storybook/client-logger": "7.0.0-alpha.38",
"@storybook/components": "7.0.0-alpha.38",
"@storybook/core-events": "7.0.0-alpha.38",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"global": "^4.4.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion code/addons/outline/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"@storybook/client-logger": "7.0.0-alpha.38",
"@storybook/components": "7.0.0-alpha.38",
"@storybook/core-events": "7.0.0-alpha.38",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"global": "^4.4.0",
"ts-dedent": "^2.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion code/addons/storyshots/storyshots-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@storybook/core-client": "7.0.0-alpha.38",
"@storybook/core-common": "7.0.0-alpha.38",
"@storybook/core-webpack": "7.0.0-alpha.38",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"@types/glob": "^7.1.3",
"@types/jest": "^26.0.16",
"@types/jest-specific-snapshot": "^0.5.3",
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": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"@storybook/node-logger": "7.0.0-alpha.38",
"@types/jest-image-snapshot": "^4.1.3",
"jest-image-snapshot": "^4.3.0"
Expand Down
2 changes: 1 addition & 1 deletion code/examples/external-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@storybook/addon-essentials": "7.0.0-alpha.38",
"@storybook/blocks": "7.0.0-alpha.38",
"@storybook/components": "7.0.0-alpha.38",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"@storybook/preview-web": "7.0.0-alpha.38",
"@storybook/react": "7.0.0-alpha.38",
"@storybook/react-webpack5": "7.0.0-alpha.38",
Expand Down
2 changes: 1 addition & 1 deletion code/frameworks/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@storybook/core-events": "7.0.0-alpha.38",
"@storybook/core-server": "7.0.0-alpha.38",
"@storybook/core-webpack": "7.0.0-alpha.38",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"@storybook/docs-tools": "7.0.0-alpha.38",
"@storybook/node-logger": "7.0.0-alpha.38",
"@storybook/store": "7.0.0-alpha.38",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/addons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@storybook/channels": "7.0.0-alpha.38",
"@storybook/client-logger": "7.0.0-alpha.38",
"@storybook/core-events": "7.0.0-alpha.38",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"@storybook/router": "7.0.0-alpha.38",
"@storybook/theming": "7.0.0-alpha.38",
"global": "^4.4.0"
Expand Down
2 changes: 1 addition & 1 deletion code/lib/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@storybook/channels": "7.0.0-alpha.38",
"@storybook/client-logger": "7.0.0-alpha.38",
"@storybook/core-events": "7.0.0-alpha.38",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"@storybook/router": "7.0.0-alpha.38",
"@storybook/theming": "7.0.0-alpha.38",
"dequal": "^2.0.2",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/blocks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@storybook/client-logger": "7.0.0-alpha.38",
"@storybook/components": "7.0.0-alpha.38",
"@storybook/core-events": "7.0.0-alpha.38",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"@storybook/docs-tools": "7.0.0-alpha.38",
"@storybook/preview-web": "7.0.0-alpha.38",
"@storybook/store": "7.0.0-alpha.38",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/client-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"dependencies": {
"@storybook/addons": "7.0.0-alpha.38",
"@storybook/client-logger": "7.0.0-alpha.38",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"@storybook/store": "7.0.0-alpha.38",
"@types/qs": "^6.9.5",
"@types/webpack-env": "^1.16.4",
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 @@ -39,7 +39,7 @@
"dependencies": {
"@babel/types": "^7.12.11",
"@mdx-js/mdx": "^1.6.22",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"@storybook/csf-tools": "7.0.0-alpha.38",
"@storybook/node-logger": "7.0.0-alpha.38",
"cross-spawn": "^7.0.3",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/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-alpha.38",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"@storybook/theming": "7.0.0-alpha.38",
"memoizerific": "^1.11.3",
"util-deprecate": "^1.0.2"
Expand Down
2 changes: 1 addition & 1 deletion code/lib/core-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@storybook/client-api": "7.0.0-alpha.38",
"@storybook/client-logger": "7.0.0-alpha.38",
"@storybook/core-events": "7.0.0-alpha.38",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"@storybook/preview-web": "7.0.0-alpha.38",
"@storybook/store": "7.0.0-alpha.38",
"@storybook/ui": "7.0.0-alpha.38",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/core-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"dependencies": {
"@babel/core": "^7.12.10",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"@storybook/node-logger": "7.0.0-alpha.38",
"@types/babel__core": "^7.0.0",
"@types/express": "^4.7.0",
Expand Down
1 change: 1 addition & 0 deletions code/lib/core-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export * from './utils/normalize-stories';
export * from './utils/readTemplate';
export * from './utils/findDistEsm';
export * from './utils/symlinks';
export * from './utils/satisfies';

export * from './types';

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion code/lib/core-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@storybook/core-client": "7.0.0-alpha.38",
"@storybook/core-common": "7.0.0-alpha.38",
"@storybook/core-events": "7.0.0-alpha.38",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"@storybook/csf-tools": "7.0.0-alpha.38",
"@storybook/docs-mdx": "0.0.1-canary.12433cf.0",
"@storybook/node-logger": "7.0.0-alpha.38",
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 @@ -46,7 +46,7 @@
"@babel/parser": "^7.12.11",
"@babel/traverse": "^7.12.11",
"@babel/types": "^7.12.11",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"fs-extra": "^9.0.1",
"ts-dedent": "^2.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion code/lib/docs-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"dependencies": {
"@babel/core": "^7.12.10",
"@storybook/core-common": "7.0.0-alpha.38",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"@storybook/store": "7.0.0-alpha.38",
"doctrine": "^3.0.0",
"lodash": "^4.17.21"
Expand Down
2 changes: 1 addition & 1 deletion code/lib/preview-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@storybook/channels": "7.0.0-alpha.38",
"@storybook/client-logger": "7.0.0-alpha.38",
"@storybook/core-events": "7.0.0-alpha.38",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"@storybook/store": "7.0.0-alpha.38",
"ansi-to-html": "^0.6.11",
"global": "^4.4.0",
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": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"estraverse": "^5.2.0",
"lodash": "^4.17.21",
"prettier": ">=2.2.1 <=2.3.0"
Expand Down
2 changes: 1 addition & 1 deletion code/lib/store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@storybook/addons": "7.0.0-alpha.38",
"@storybook/client-logger": "7.0.0-alpha.38",
"@storybook/core-events": "7.0.0-alpha.38",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"dequal": "^2.0.2",
"global": "^4.4.0",
"lodash": "^4.17.21",
Expand Down
2 changes: 1 addition & 1 deletion code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@
"ts-jest": "^26.4.4",
"ts-node": "^10.4.0",
"tsup": "^6.2.2",
"typescript": "4.7.4",
"typescript": "~4.6.3",
"util": "^0.12.4",
"vite": "^3.1.7",
"wait-on": "^5.2.1",
Expand Down
2 changes: 1 addition & 1 deletion code/renderers/html/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"dependencies": {
"@storybook/addons": "7.0.0-alpha.38",
"@storybook/core-client": "7.0.0-alpha.38",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"@storybook/docs-tools": "7.0.0-alpha.38",
"@storybook/preview-web": "7.0.0-alpha.38",
"@storybook/store": "7.0.0-alpha.38",
Expand Down
2 changes: 1 addition & 1 deletion code/renderers/preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"dependencies": {
"@storybook/addons": "7.0.0-alpha.38",
"@storybook/core-client": "7.0.0-alpha.38",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"@storybook/store": "7.0.0-alpha.38",
"global": "^4.4.0",
"react": "16.14.0",
Expand Down
2 changes: 1 addition & 1 deletion code/renderers/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"@storybook/addons": "7.0.0-alpha.38",
"@storybook/client-logger": "7.0.0-alpha.38",
"@storybook/core-client": "7.0.0-alpha.38",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"@storybook/docs-tools": "7.0.0-alpha.38",
"@storybook/store": "7.0.0-alpha.38",
"@types/estree": "^0.0.51",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React, { KeyboardEventHandler, ReactNode } from 'react';
import { expectTypeOf } from 'expect-type';
import { describe, test } from '@jest/globals';
import { satisfies } from '@storybook/core-common';
import { StoryAnnotations } from '@storybook/csf';
import { expectTypeOf } from 'expect-type';
import React, { KeyboardEventHandler, ReactNode } from 'react';
import { SetOptional } from 'type-fest';

import { Meta, StoryObj } from '../public-types';
import { DecoratorFn } from '../public-api';
import { satisfies } from './utils';
import { ReactFramework } from '../types';
import { DecoratorFn } from './public-api';
import { Meta, StoryObj } from './public-types';
import { ReactFramework } from './types';

type ReactStory<Args, RequiredArgs> = StoryAnnotations<ReactFramework, Args, RequiredArgs>;

Expand Down Expand Up @@ -75,6 +75,11 @@ describe('Args can be provided in multiple ways', () => {
expectTypeOf(Basic).toEqualTypeOf<Expected>();
}
});

test('Component can be used as generic parameter for StoryObj', () => {
type Expected = ReactStory<ButtonProps, ButtonProps>;
expectTypeOf<StoryObj<typeof Button>>().toEqualTypeOf<Expected>();
});
});

test('✅ All void functions are optional', () => {
Expand Down
34 changes: 16 additions & 18 deletions code/renderers/react/src/public-types.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import type {
AnnotatedStoryFn,
Args,
ArgsFromMeta,
ArgsStoryFn,
ComponentAnnotations,
LoaderFunction,
StoryAnnotations,
} from '@storybook/csf';
import { SetOptional, Simplify, UnionToIntersection } from 'type-fest';
import { ComponentProps, ComponentType, JSXElementConstructor } from 'react';
import { SetOptional, Simplify } from 'type-fest';

import { ReactFramework } from './types';
import { DecoratorFn } from './public-api';

type JSXElement = keyof JSX.IntrinsicElements | JSXElementConstructor<any>;

Expand All @@ -36,29 +35,28 @@ export type StoryFn<TArgs = Args> = AnnotatedStoryFn<ReactFramework, TArgs>;
* @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
*/

export type StoryObj<MetaOrArgs = Args> = MetaOrArgs extends {
render?: ArgsStoryFn<ReactFramework, infer RArgs>;
component?: ComponentType<infer CmpArgs>;
loaders?: (infer Loaders)[];
export type StoryObj<MetaOrCmpOrArgs = Args> = MetaOrCmpOrArgs extends {
render?: ArgsStoryFn<ReactFramework, any>;
component?: infer Component;
args?: infer DefaultArgs;
decorators?: (infer Decorators)[];
}
? Simplify<CmpArgs & RArgs & DecoratorsArgs<Decorators> & LoaderArgs<Loaders>> extends infer TArgs
? Simplify<
(Component extends ComponentType<any> ? ComponentProps<Component> : unknown) &
ArgsFromMeta<ReactFramework, MetaOrCmpOrArgs>
> extends infer TArgs
? StoryAnnotations<
ReactFramework,
TArgs,
SetOptional<TArgs, Extract<keyof TArgs, keyof (DefaultArgs & ActionArgs<TArgs>)>>
>
: never
: StoryAnnotations<ReactFramework, MetaOrArgs>;

type DecoratorsArgs<Decorators> = UnionToIntersection<
Decorators extends DecoratorFn<infer Args> ? Args : unknown
>;

type LoaderArgs<Loaders> = UnionToIntersection<
Loaders extends LoaderFunction<ReactFramework, infer Args> ? Args : unknown
>;
: MetaOrCmpOrArgs extends ComponentType<any>
? StoryAnnotations<
ReactFramework,
ComponentProps<MetaOrCmpOrArgs>,
ComponentProps<MetaOrCmpOrArgs>
>
: StoryAnnotations<ReactFramework, MetaOrCmpOrArgs>;

type ActionArgs<Args> = {
[P in keyof Args as ((...args: any[]) => void) extends Args[P] ? P : never]: Args[P];
Expand Down
2 changes: 1 addition & 1 deletion code/renderers/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"dependencies": {
"@storybook/addons": "7.0.0-alpha.38",
"@storybook/core-client": "7.0.0-alpha.38",
"@storybook/csf": "0.0.2--canary.49.258942b.0",
"@storybook/csf": "0.0.2--canary.51.23af5af.0",
"@storybook/preview-web": "7.0.0-alpha.38",
"@storybook/store": "7.0.0-alpha.38",
"global": "^4.4.0",
Expand Down
Loading

0 comments on commit 7c1b9cc

Please sign in to comment.