Open Hurtak opened 1 year ago
I think not applying Partial
here would fix this this (threw an error) https://github.com/tajo/ladle/blob/main/packages/ladle/lib/app/exports.ts#L94C5-L94C12
@wojtekmaj any thoughts on this?
The problem I was aiming to address with Partial is in my opinion bigger than the one reported here, and I don't know if I have a solution to make everyone happy. In reality many stories would change one, maybe two props, leaving others at their defaults, making them pretty good, isolated and readable test cases. Consider the following, if Partial was missing:
export const Test: Story<TestComponentProps> = (props) => <TestComponent requiredB={2} {...props} />;
Test.args = {
requiredA: () => 1,
// ^ tsc/linter/build would crash despite the fact in reality it would have rendered just fine
};
should we have Story
and StoryRequired
types?
Sounds like a plan!
Yea I think the StoryRequired
should solve this.
One think to consider might be: the pattern mentioned in https://github.com/tajo/ladle/issues/515#issuecomment-1742446858, that would break if Partial was missing, seems not to be that common (at least by briefly looking at our stories, it is less than 10% of stories), so maybe we could make the Story
type strict (without Partial) and introduce StoryPartial
for these cases? This would probably be a breaking change, so not sure if it is worth it, but having safer default seems like a good thing to do.
I think it is quite valuable to have some way to render all stories. Missing props is just one possible reason for a story to be broken. It's important is to check the stories in runtime, not just static type checking (if it does both, even better).
In my opinion, best way is if this could be done by just creating a test for each story. Not sure how difficult is to deal with support for different test runners though.
But if it's done by some separate command like ladle verify
as suggested (possibly using Vitest, since Ladle already uses Vite), that's fine too.
Is your feature request related to a problem? Please describe.
What happened a bunch of time to me is
Story<Props>
type +.args
pattern (that is AFAIK the recommended way to do it in the docs) the story crashesWe do have
tsc
+eslint
+ladle build
in our CI pipeline and none of these catches that the story is no longer workingDescribe the solution you'd like
2 solutions come to my mind
ladle verify
) that would actually render all of the stories and report if some of them render error?Additional context
component
story