Skip to content
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

Sound arg types for CSF3 #49

Merged
merged 11 commits into from
Oct 22, 2022
Merged

Sound arg types for CSF3 #49

merged 11 commits into from
Oct 22, 2022

Conversation

kasperpeulen
Copy link
Contributor

@kasperpeulen kasperpeulen commented Oct 4, 2022

Strict args

export type StoryAnnotations<
  TFramework extends AnyFramework = AnyFramework,
  TArgs = Args,
  TArgsAnnotations = Partial<TArgs>
> 

Added a third argument, for the args that need to be annotated for a story (which may be different then "all" the args, which is TArgs). This allows frameworks to provide strict args without specifying args that are already filled in automagically.

Strict component in meta:
Made AnyFramework dependent on a generic parameter T, which makes sure we can use the Framework['component'] with different generic values ( we use any/unknown,TArgs).

This ensures that the component provided in meta, must match TArgs, while subcomponents and other references of Framework['component'] stay more generic.

Strict decorators/loaders:
Loaders and decorators are now dependent on TArgs, which means you get auto-completion and typesafety when using args.

decorators: [(Story, { args }) => (
    <>
      Decorator: {args.sometingOnTArgs}
      <Story args={{ otherThingonTArgs: 0 }} /> // I also changed this to accept {args?: Partial<TArgs>} instead of {args?: TArgs}
    </>
  )
]
📦 Published PR as canary version: 0.0.2--canary.49.65292c2.0

✨ Test out this PR locally via:

npm install @storybook/[email protected]
# or 
yarn add @storybook/[email protected]

@kasperpeulen kasperpeulen changed the base branch from next to add-step October 4, 2022 15:21
@kasperpeulen kasperpeulen changed the title WIP: Sound arg types fort CSF3 Sound arg types fort CSF3 Oct 6, 2022
Copy link
Contributor

@tmeasday tmeasday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I have a couple questions for my own clarification, and one minor suggestion.

src/story.ts Show resolved Hide resolved
src/story.ts Outdated

export type StoryAnnotations<
TFramework extends AnyFramework = AnyFramework,
TArgs = Args
TArgs = Args,
TArgsAnnotations = Partial<TArgs>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TArgsAnnotations = Partial<TArgs>
TRequiredArgs = Partial<TArgs>

This is more intuitive to me, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me, what do you think @shilman?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me. Also discussed TRemainingArgs because these args are not necessarily required. But agree that "required" is the most readable/clear

src/story.ts Outdated Show resolved Hide resolved
@shilman shilman changed the title Sound arg types fort CSF3 Sound arg types for CSF3 Oct 10, 2022
@shilman
Copy link
Contributor

shilman commented Apr 3, 2023

🚀 PR was released in v0.1.0 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants