-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Expose more CSF types in all renderers #19833
Conversation
Can you elaborate on this? I though addons would be a perfect usecase for augmenting types based on the user's setup, but maybe I'm misunderstanding you. |
Yes, I do think that addons are a perfect usecase for module augmentation, but I do think the "actual" module augmentation should happen in app code, and not in the library code of the addon. I think the addon should export types like // for example in [app]/src/types.d.ts
import type { AngularParameters, StorybookParameters } from '@storybook/angular';
import type { ChromaticParameters } from 'chromatic';
import type { DocsParameters } from '@storybook/addon-docs';
import type { BackgroundsParameters } from '@storybook/addon-backgrounds';
declare module '@storybook/angular' {
interface Parameters
extends StorybookParameters,
AngularParameters,
ChromaticParameters,
DocsParameters,
BackgroundsParameters {}
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really good stuff, @kasperpeulen !
Issue:
What I did
Args
,ArgTypes
,Parameters
andStrictArgs
in all renderersStoryContext
parametrized for the specificRenderer
Decorator
,Loader
which are also parametrized for the specificRenderer
DecoratorFn
as I renamed it toDecorator
for 7. This allows for making a breaking change to the DecoratorFn type. It now defaults to a more Strict version ofArgs
. Making this strict was necessary so thatany
doesn't mess up type inference ofMeta
in the new strictStoryObj
.Lastly, I changed the export of
@storybook/types
to be the bareParameters
again of@storybook/csf
and made a newStorybookParameters
andStorybookInternalParameters
in@storybook/types
.The reason is that going forward we want users to have autocompletion for
Parameters
, that is specific to their setup. The easiest way for users to do this, is using module augmentation:This only works, if the export of
Parameters
, is actually a direct reference to the interface defined in@storybook/csf
.I think we should also offer users a way to achieve autocompletion for Parameters without module augmentation. Especially, in the case of libraries, such as addons, using module augmentation should be discouraged, as it can have unintended side effects.
Next to module augmentation, we could also offer users to parametrize
Parameters
themself as well:I didn't expose the
StorybookParameters
, as I want to first check the quality of it, and make sure that is complete.Also I made an
InternalStorybookParameters
interface, as I had the feeling that we don't want to exposefileName
anddocsOnly
to the user, as they should not be set by users I believe.