Skip to content

Commit

Permalink
Allow TS type cast default export (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
tajo committed May 11, 2022
1 parent fa8db60 commit 515d069
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/large-hairs-drop.md
@@ -0,0 +1,5 @@
---
"@ladle/react": patch
---

Allow typescript typecast default export syntax when parsing stories.
Expand Up @@ -12,6 +12,9 @@ const getDefaultExport = (result, astPath) => {
objNode =
astPath.scope.bindings[astPath.node.declaration.name].path.node.init;
}
if (astPath.node.declaration.type === "TSAsExpression") {
objNode = astPath.node.declaration.expression;
}
objNode.properties.forEach((/** @type {any} */ prop) => {
if (prop.type === "ObjectProperty" && prop.key.name === "title") {
if (prop.value.type !== "StringLiteral") {
Expand All @@ -29,6 +32,7 @@ const getDefaultExport = (result, astPath) => {
}
});
} catch (e) {
console.log(e);
throw new Error(
`Can't parse the default title and meta of ${result.entry}. Meta must be serializable and title a string literal.`,
);
Expand Down

1 comment on commit 515d069

@vercel
Copy link

@vercel vercel bot commented on 515d069 May 11, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

ladle – ./

ladle-git-master-miksu.vercel.app
ladle.vercel.app
ladle-miksu.vercel.app
ladle.dev

Please sign in to comment.