-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Svelte: Improve CSF3 types #19512
Svelte: Improve CSF3 types #19512
Conversation
9563ce7
to
c637e76
Compare
Socket Security Report👍 No new dependency issues detected in pull request Socket.dev scan summary
Bot CommandsTo ignore an alert, reply with a comment starting with Powered by socket.dev |
387630a
to
44b95f0
Compare
247d211
to
7c1b9cc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR description mentions TypeScript 4.9, but that's not released yet and it looks like this is using ~4.6.3
?
It looks like there's tons of merge conflicts on this PR
@benmccann Yes, I'm working on upgrading to TS 4.9 in this branch: But that is blocked by TS 4.9 being released (and the ecosystem around it ESLint and prettier). This PR can be merged independently of that though, as Resolving the merge conflicts 😅 |
# Conflicts: # code/addons/a11y/package.json # code/addons/actions/package.json # code/addons/backgrounds/package.json # code/addons/controls/package.json # code/addons/docs/package.json # code/addons/interactions/package.json # code/addons/links/package.json # code/addons/measure/package.json # code/addons/outline/package.json # code/addons/storyshots/storyshots-core/package.json # code/addons/storyshots/storyshots-puppeteer/package.json # code/examples/external-docs/package.json # code/frameworks/angular/package.json # code/lib/addons/package.json # code/lib/api/package.json # code/lib/blocks/package.json # code/lib/client-api/package.json # code/lib/codemod/package.json # code/lib/components/package.json # code/lib/core-client/package.json # code/lib/core-common/package.json # code/lib/core-server/package.json # code/lib/docs-tools/package.json # code/lib/preview-web/package.json # code/lib/store/package.json # code/renderers/html/package.json # code/renderers/preact/package.json # code/renderers/react/package.json # code/renderers/server/package.json # code/renderers/svelte/package.json # code/renderers/vue/package.json # code/renderers/vue3/package.json # code/renderers/web-components/package.json # code/ui/manager/package.json # code/yarn.lock
# Conflicts: # code/lib/core-common/src/index.ts
# Conflicts: # code/addons/a11y/package.json # code/addons/actions/package.json # code/addons/backgrounds/package.json # code/addons/controls/package.json # code/addons/docs/package.json # code/addons/interactions/package.json # code/addons/links/package.json # code/addons/measure/package.json # code/addons/outline/package.json # code/addons/storyshots/storyshots-core/package.json # code/addons/storyshots/storyshots-puppeteer/package.json # code/examples/external-docs/package.json # code/frameworks/angular/package.json # code/lib/addons/package.json # code/lib/api/package.json # code/lib/blocks/package.json # code/lib/client-api/package.json # code/lib/codemod/package.json # code/lib/components/package.json # code/lib/core-client/package.json # code/lib/core-common/package.json # code/lib/core-server/package.json # code/lib/docs-tools/package.json # code/lib/preview-web/package.json # code/lib/store/package.json # code/renderers/html/package.json # code/renderers/preact/package.json # code/renderers/react/package.json # code/renderers/server/package.json # code/renderers/svelte/package.json # code/renderers/vue/package.json # code/renderers/vue3/package.json # code/renderers/web-components/package.json # code/ui/manager/package.json # code/yarn.lock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really good!
I'm still not sure what the impact is of using satisfies
and TS 4.9 for our users, but I think you've discussed this earlier with people so I trust that it is under control.
@@ -335,7 +336,7 @@ | |||
"ts-jest": "^26.4.4", | |||
"ts-node": "^10.4.0", | |||
"tsup": "^6.2.2", | |||
"typescript": "4.7.4", | |||
"typescript": "~4.6.3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
downgrade?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More likely ensuring we use the same version everywhere.
@@ -0,0 +1,230 @@ | |||
import { describe, test } from '@jest/globals'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love these type tests. 💪
"strict": true, | ||
"resolveJsonModule": true | ||
}, | ||
"include": ["src/**/*"], | ||
"exclude": ["src/**/*.test.*"] | ||
"exclude": [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unless this has an effect, I'd remove this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think It's likely required, because of:
Lines 20 to 29 in 962ed90
"exclude": [ | |
"dist", | |
"**/dist", | |
"node_modules", | |
"**/node_modules", | |
"**/*.spec.ts", | |
"**/__tests__", | |
"**/*.test.ts", | |
"**/setup-jest.ts" | |
], |
# Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit.
What I did
This PR provides improved type safety for Svelte stories (similar to what we changed to React) but requires svelte-check instead of tsc (Svelte for VS Code extension for editor support):
https://github.com/sveltejs/language-tools/tree/master/packages/svelte-check
Requires the satisfies keyword available in TS ≥ 4.9:
microsoft/TypeScript#46827
Built on top of this CSF PR:
ComponentDriven/csf#51
Typesafe args
We changed
StoryObj
andMeta
to increase type safety for when the user provides args partially in meta.Considering a Component like this:
It is valid to provide args like this:
While it is invalid to forget an arg, in either meta or the story:
Changed Meta to make sure both a Component, as the Props of the component can be used:
If the component is used, you will have enhanced autocompletion for events (maybe in a future version also for slots, when we support that):
Typesafe decorators/loaders
Decorators now accept a new generic arg argument to be specified:
And the type of meta/story will check if this arg is part of the generic type:
How to test
You can test it by running:
yarn nx run @storybook/svelte:check
@benmccann @j3rem1e If you could have a look :)