Skip to content

Commit

Permalink
Merge pull request #28503 from storybookjs/valentin/fix-core-dist-typ…
Browse files Browse the repository at this point in the history
…e-creation

Types: Update type signatures of objects and functions
  • Loading branch information
valentinpalkovic authored Jul 10, 2024
2 parents 3b04c5b + 8be78f2 commit 6598f73
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 12 deletions.
3 changes: 2 additions & 1 deletion code/frameworks/nextjs/src/portable-stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
Store_CSFExports,
StoriesWithPartialProps,
NamedOrDefaultProjectAnnotations,
ComposedStoryFn,
} from 'storybook/internal/types';

// ! ATTENTION: This needs to be a relative import so it gets prebundled. This is to avoid ESM issues in Nextjs + Jest setups
Expand Down Expand Up @@ -80,7 +81,7 @@ export function composeStory<TArgs extends Args = Args>(
componentAnnotations: Meta<TArgs | any>,
projectAnnotations?: ProjectAnnotations<ReactRenderer>,
exportsName?: string
) {
): ComposedStoryFn<ReactRenderer, Partial<TArgs>> {
return originalComposeStory<ReactRenderer, TArgs>(
story as StoryAnnotationsOrFn<ReactRenderer, Args>,
componentAnnotations,
Expand Down
2 changes: 1 addition & 1 deletion code/renderers/react/src/docs/extractArgTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { StrictArgTypes } from 'storybook/internal/types';
import type { PropDef, ArgTypesExtractor } from 'storybook/internal/docs-tools';
import { extractProps } from './extractProps';

export const extractArgTypes: ArgTypesExtractor = (component) => {
export const extractArgTypes: ArgTypesExtractor = (component): StrictArgTypes | null => {
if (component) {
const { rows } = extractProps(component);
if (rows) {
Expand Down
11 changes: 10 additions & 1 deletion code/renderers/react/src/entry-preview-docs.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import type { ArgTypesEnhancer, DecoratorFunction } from 'storybook/internal/types';
import type { ArgTypesExtractor } from 'storybook/internal/docs-tools';
import { extractComponentDescription, enhanceArgTypes } from 'storybook/internal/docs-tools';

import { extractArgTypes } from './docs/extractArgTypes';
import { jsxDecorator } from './docs/jsxDecorator';
import type { ReactRenderer } from './types';

export const parameters = {
export const parameters: {
docs: {
story: {
inline: boolean;
};
extractArgTypes: ArgTypesExtractor;
extractComponentDescription: (component?: any) => string;
};
} = {
docs: {
story: { inline: true },
extractArgTypes,
Expand Down
3 changes: 2 additions & 1 deletion code/renderers/react/src/portable-stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
Store_CSFExports,
StoriesWithPartialProps,
ProjectAnnotations,
ComposedStoryFn,
} from 'storybook/internal/types';

import * as reactProjectAnnotations from './entry-preview';
Expand Down Expand Up @@ -85,7 +86,7 @@ export function composeStory<TArgs extends Args = Args>(
componentAnnotations: Meta<TArgs | any>,
projectAnnotations?: ProjectAnnotations<ReactRenderer>,
exportsName?: string
) {
): ComposedStoryFn<ReactRenderer, Partial<TArgs>> {
return originalComposeStory<ReactRenderer, TArgs>(
story as StoryAnnotationsOrFn<ReactRenderer, Args>,
componentAnnotations,
Expand Down
4 changes: 3 additions & 1 deletion code/renderers/svelte/src/docs/extractArgTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ function hasKeyword(keyword: string, keywords: JSDocKeyword[]): boolean {
return keywords ? keywords.find((k) => k.name === keyword) != null : false;
}

export const extractArgTypes: ArgTypesExtractor = (component: ComponentWithDocgen) => {
export const extractArgTypes: ArgTypesExtractor = (
component: ComponentWithDocgen
): StrictArgTypes | null => {
try {
// eslint-disable-next-line no-underscore-dangle
const docgen = component.__docgen;
Expand Down
11 changes: 10 additions & 1 deletion code/renderers/svelte/src/entry-preview-docs.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import type { ArgTypesEnhancer, DecoratorFunction } from 'storybook/internal/types';
import type { ArgTypesExtractor } from 'storybook/internal/docs-tools';
import { enhanceArgTypes } from 'storybook/internal/docs-tools';
import { extractArgTypes } from './docs/extractArgTypes';
import { extractComponentDescription } from './docs/extractComponentDescription';
import { sourceDecorator } from './docs/sourceDecorator';
import type { SvelteRenderer } from './types';

export const parameters = {
export const parameters: {
docs: {
story: {
inline: boolean;
};
extractArgTypes: ArgTypesExtractor;
extractComponentDescription: (component?: any) => string;
};
} = {
docs: {
story: { inline: true },
extractArgTypes,
Expand Down
2 changes: 1 addition & 1 deletion code/renderers/svelte/src/portable-stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export function composeStory<TArgs extends Args = Args>(
componentAnnotations: Meta<TArgs | any>,
projectAnnotations?: ProjectAnnotations<SvelteRenderer>,
exportsName?: string
) {
): ComposedStory<TArgs> {
const composedStory = originalComposeStory<SvelteRenderer, TArgs>(
story as StoryAnnotationsOrFn<SvelteRenderer, Args>,
// @ts-expect-error Fix this later: Type 'Partial<{ [x: string]: any; }>' is not assignable to type 'Partial<Simplify<TArgs, {}>>'
Expand Down
2 changes: 1 addition & 1 deletion code/renderers/vue3/src/docs/extractArgTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type PropertyMetaSchema = VueDocgenInfoEntry<'vue-component-meta', 'props'>['sch
// "exposed" is used by the vue-component-meta plugin while "expose" is used by vue-docgen-api
const ARG_TYPE_SECTIONS = ['props', 'events', 'slots', 'exposed', 'expose'] as const;

export const extractArgTypes: ArgTypesExtractor = (component) => {
export const extractArgTypes: ArgTypesExtractor = (component): StrictArgTypes | null => {
if (!hasDocgen<VueDocgenInfo<VueDocgenPlugin>>(component)) {
return null;
}
Expand Down
11 changes: 10 additions & 1 deletion code/renderers/vue3/src/entry-preview-docs.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import type { ArgTypesEnhancer, DecoratorFunction } from 'storybook/internal/types';
import type { ArgTypesExtractor } from 'storybook/internal/docs-tools';
import { extractComponentDescription, enhanceArgTypes } from 'storybook/internal/docs-tools';
import { extractArgTypes } from './docs/extractArgTypes';
import { sourceDecorator } from './docs/sourceDecorator';
import type { VueRenderer } from './types';

export const parameters = {
export const parameters: {
docs: {
story: {
inline: boolean;
};
extractArgTypes: ArgTypesExtractor;
extractComponentDescription: (component?: any) => string;
};
} = {
docs: {
story: { inline: true },
extractArgTypes,
Expand Down
3 changes: 2 additions & 1 deletion code/renderers/vue3/src/portable-stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
StoryAnnotationsOrFn,
Store_CSFExports,
StoriesWithPartialProps,
ComposedStoryFn,
} from 'storybook/internal/types';
import { TestingLibraryMustBeConfiguredError } from 'storybook/internal/preview-errors';
import { h } from 'vue';
Expand Down Expand Up @@ -91,7 +92,7 @@ export function composeStory<TArgs extends Args = Args>(
componentAnnotations: Meta<TArgs | any>,
projectAnnotations?: ProjectAnnotations<VueRenderer>,
exportsName?: string
) {
): JSXAble<ComposedStoryFn<VueRenderer, Partial<TArgs>>> {
const composedStory = originalComposeStory<VueRenderer, TArgs>(
story as StoryAnnotationsOrFn<VueRenderer, Args>,
componentAnnotations,
Expand Down
21 changes: 19 additions & 2 deletions code/renderers/web-components/src/entry-preview-docs.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
import type { ArgTypesEnhancer, DecoratorFunction } from 'storybook/internal/types';
import type { ArgTypesEnhancer, DecoratorFunction, InputType } from 'storybook/internal/types';
import { SourceType, enhanceArgTypes } from 'storybook/internal/docs-tools';
import { extractArgTypes, extractComponentDescription } from './docs/custom-elements';
import { sourceDecorator } from './docs/sourceDecorator';
import type { WebComponentsRenderer } from './types';

export const decorators: DecoratorFunction<WebComponentsRenderer>[] = [sourceDecorator];

export const parameters = {
export const parameters: {
docs: {
extractArgTypes: (tagName: string) =>
| {
[x: string]: InputType;
}
| null
| undefined;
extractComponentDescription: (tagName: string) => string | null | undefined;
story: {
inline: true;
};
source: {
type: SourceType;
language: string;
};
};
} = {
docs: {
extractArgTypes,
extractComponentDescription,
Expand Down

0 comments on commit 6598f73

Please sign in to comment.