Skip to content

Commit

Permalink
Merge pull request #20088 from storybookjs/shilman/support-ts-satisfies
Browse files Browse the repository at this point in the history
CSF: Add satisfies support to csf-tools
  • Loading branch information
shilman authored Dec 5, 2022
2 parents b2e0a8a + 4872094 commit 7af491a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
45 changes: 45 additions & 0 deletions code/lib/csf-tools/src/CsfFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,28 @@ describe('CsfFile', () => {
`);
});

it('typescript satisfies', () => {
expect(
parse(
dedent`
import type { Meta, StoryFn } from '@storybook/react';
type PropTypes = {};
export default { title: 'foo/bar/baz' } as Meta<PropTypes>;
export const A: StoryFn<PropTypes> = () => <>A</>;
export const B: StoryFn<PropTypes> = () => <>B</>;
`
)
).toMatchInlineSnapshot(`
meta:
title: foo/bar/baz
stories:
- id: foo-bar-baz--a
name: A
- id: foo-bar-baz--b
name: B
`);
});

it('typescript meta var', () => {
expect(
parse(
Expand All @@ -244,6 +266,29 @@ describe('CsfFile', () => {
`);
});

it('typescript satisfies meta var', () => {
expect(
parse(
dedent`
import type { Meta, StoryFn } from '@storybook/react';
type PropTypes = {};
const meta = { title: 'foo/bar/baz' } satisfies Meta<PropTypes>;
export default meta;
export const A: StoryFn<PropTypes> = () => <>A</>;
export const B: StoryFn<PropTypes> = () => <>B</>;
`
)
).toMatchInlineSnapshot(`
meta:
title: foo/bar/baz
stories:
- id: foo-bar-baz--a
name: A
- id: foo-bar-baz--b
name: B
`);
});

it('component object', () => {
expect(
parse(
Expand Down
2 changes: 1 addition & 1 deletion code/lib/csf-tools/src/CsfFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ export class CsfFile {
metaNode = decl;
} else if (
// export default { ... } as Meta<...>
t.isTSAsExpression(decl) &&
(t.isTSAsExpression(decl) || t.isTSSatisfiesExpression(decl)) &&
t.isObjectExpression(decl.expression)
) {
metaNode = decl.expression;
Expand Down

0 comments on commit 7af491a

Please sign in to comment.