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

CSF-tools: Allow type checking in story title #22791

Merged
merged 4 commits into from
Jul 3, 2023

Conversation

honzahruby
Copy link
Contributor

What I did

V7 disallows using expressions and variables for story titles. This PR allows the title to conform to a certain (nested) structure using satisfies operator.

How to test

Run storybook on this branch and use satisfies in the story title definition

enum ComponentGroups {
    General = 'General'
}
type ComponentTitle<Group extends ComponentGroups> = `${Group}/${string}`;

export default {
    title: 'General/Button' satisfies ComponentTitle<ComponentGroups.General>,
    component: Button,
};

Checklist

  • Make sure your changes are tested (stories and/or unit, integration, or end-to-end tests)
  • Make sure to add/update documentation regarding your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Maintainers

  • If this PR should be tested against many or all sandboxes,
    make sure to add the ci:merged or ci:daily GH label to it.
  • Make sure this PR contains one of the labels below.

["cleanup", "BREAKING CHANGE", "feature request", "bug", "documentation", "maintenance", "dependencies", "other"]

Copy link
Contributor

@kasperpeulen kasperpeulen left a comment

Choose a reason for hiding this comment

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

Looks good in general, but we would like to remain specific about what a title can be, even if it is a satisfies expression.

Comment on lines 171 to 176
if (t.isTSSatisfiesExpression(node)) return node.expression.value;

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like we want here that satisfies expression only be able to contain a string then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolutely, thank you for pointing that out 👍
I just wanted to hotfix it for my personal use and then forgot about this condition while making it public

Copy link
Contributor

@kasperpeulen kasperpeulen left a comment

Choose a reason for hiding this comment

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

LGTM!

@honzahruby
Copy link
Contributor Author

What can I do to get this merged?

@shilman shilman changed the title Allow type checking in story title CSF-tools: Allow type checking in story title Jul 3, 2023
@shilman shilman merged commit 6878ceb into storybookjs:next Jul 3, 2023
@github-actions github-actions bot mentioned this pull request Jul 3, 2023
7 tasks
@honzahruby honzahruby deleted the patch-1 branch July 3, 2023 19:33
@shilman shilman added maintenance User-facing maintenance tasks and removed feature request labels Jul 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
csf maintenance User-facing maintenance tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants