Skip to content

Commit b832db2

Browse files
authored
Merge pull request #103 from lburgess/bugfix/component-annotations-subcomponents-type
fix: story ComponentAnnotations['subcomponents'] to correctly use its own type for subcomponents rather than attempt to inherit from the component
2 parents 2560342 + 81ecdd0 commit b832db2

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/story.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
/* global HTMLElement */
44
import { expectTypeOf } from 'expect-type';
55
import {
6-
Renderer,
76
Args,
87
ArgsFromMeta,
98
ArgsStoryFn,
109
ComponentAnnotations,
1110
DecoratorFunction,
1211
LoaderFunction,
1312
ProjectAnnotations,
13+
Renderer,
1414
StoryAnnotationsOrFn,
1515
StrictArgs,
1616
} from './story.js';
@@ -34,6 +34,8 @@ type ButtonArgs = {
3434

3535
const Button = (props: ButtonArgs) => 'Button';
3636

37+
const ButtonIcon = ({ icon }: { icon: string }) => `ButtonIcon ${icon}`;
38+
3739
let a = 1;
3840
async function doSomething() {
3941
a = 2;
@@ -118,6 +120,22 @@ CSF1Story.story = {
118120
args: { a: 1 },
119121
};
120122

123+
const simpleWithSubComponents: XMeta = {
124+
title: 'simple',
125+
component: Button,
126+
tags: ['foo', 'bar'],
127+
decorators: [(storyFn, context) => `withDecorator(${storyFn(context)})`],
128+
parameters: { a: () => null, b: NaN, c: Symbol('symbol') },
129+
loaders: [() => Promise.resolve({ d: '3' })],
130+
async beforeEach() {
131+
await doSomething();
132+
return cleanup;
133+
},
134+
args: { x: '1' },
135+
argTypes: { x: { type: { name: 'string' } } },
136+
subcomponents: { ButtonIcon }, // the fact that this line does not cause a Typescript compilation error itself means that the type is correct
137+
};
138+
121139
const CSF2Story: XStory = () => 'Named Story';
122140
CSF2Story.storyName = 'Another name for story';
123141
CSF2Story.tags = ['foo', 'bar'];

src/story.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ export interface ComponentAnnotations<TRenderer extends Renderer = Renderer, TAr
538538
*
539539
* By defining them each component will have its tab in the args table.
540540
*/
541-
subcomponents?: Record<string, TRenderer['component']>;
541+
subcomponents?: Record<string, (TRenderer & { T: any })['component']>;
542542

543543
/**
544544
* Function that is executed after the story is rendered.

0 commit comments

Comments
 (0)