-
Notifications
You must be signed in to change notification settings - Fork 47
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
ArgsFromMeta utility and generic ArgsStoryFn RT #51
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Test | ||
|
||
on: [push] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Use Node.js 14.x | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 14.x | ||
|
||
- name: Install dependencies | ||
uses: bahmutov/npm-install@v1 | ||
|
||
- name: Check typescript | ||
run: | | ||
yarn run check | ||
|
||
- name: Check linter | ||
run: | | ||
yarn lint | ||
|
||
- name: Run tests | ||
run: | | ||
yarn test |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
/* global HTMLElement, AbortSignal */ | ||
import { Simplify, UnionToIntersection } from 'type-fest'; | ||
import { SBType, SBScalarType } from './SBType'; | ||
|
||
export * from './SBType'; | ||
|
@@ -142,7 +144,7 @@ export type LegacyStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs | |
export type ArgsStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = ( | ||
args: TArgs, | ||
context: StoryContext<TFramework, TArgs> | ||
) => TFramework['storyResult']; | ||
) => (TFramework & { T: TArgs })['storyResult']; | ||
|
||
// This is either type of user story function | ||
export type StoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = | ||
|
@@ -332,3 +334,19 @@ export type AnnotatedStoryFn< | |
export type StoryAnnotationsOrFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = | ||
| AnnotatedStoryFn<TFramework, TArgs> | ||
| StoryAnnotations<TFramework, TArgs>; | ||
|
||
export type ArgsFromMeta<TFramework extends AnyFramework, Meta> = Meta extends { | ||
render?: ArgsStoryFn<TFramework, infer RArgs>; | ||
loaders?: (infer Loaders)[]; | ||
decorators?: (infer Decorators)[]; | ||
} | ||
Comment on lines
+338
to
+342
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we have a TS "test" for this? At the very least it would document what it is for :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hehe, yeah, good point, I have tests for it in this PR: I was not really sure where to put this. I could also have put it somewhere in the monorepo. Because StoryObj will now use Meta(OrArgs) as generic (typeof meta), I will need something like this in the public types of every renderer (we use it now only for react and svelte). But because there is also framework-specific inference (to infer the args of the component or specific stuff for action arg inference) I can not put all of StoryObj in this package. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added a test now |
||
? Simplify<RArgs & DecoratorsArgs<TFramework, Decorators> & LoaderArgs<TFramework, Loaders>> | ||
: unknown; | ||
|
||
type DecoratorsArgs<TFramework extends AnyFramework, Decorators> = UnionToIntersection< | ||
Decorators extends DecoratorFunction<TFramework, infer TArgs> ? TArgs : unknown | ||
>; | ||
|
||
type LoaderArgs<TFramework extends AnyFramework, Loaders> = UnionToIntersection< | ||
Loaders extends LoaderFunction<TFramework, infer TArgs> ? TArgs : unknown | ||
>; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"target": "ES2022", | ||
"lib": ["es2015", "es2017", "dom"], | ||
"module": "commonjs", | ||
"moduleResolution": "Node", | ||
"module": "ES2022", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The storybook monorepo is still using:
This seems like quite a jump. Is this going to impact our chrome 100+ support target? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the storybook monorepo the tsconfig isn't used to determine the compile target at all There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it being used in this case? If so, is this the correct target? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might not matter at all, depending on the source code. but let's play it safe and target 2020? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tomorrow, was a long day π There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
"declaration": true, | ||
"removeComments": true, | ||
"strict": true, | ||
"noImplicitAny": true, | ||
"esModuleInterop": true, | ||
"outDir": "dist" | ||
"outDir": "dist", | ||
"skipLibCheck": true, | ||
"noEmit": true | ||
}, | ||
"include": ["src"], | ||
"exclude": ["src/**/*.test.ts", "dist"] | ||
"exclude": ["dist", "src/includeConditionalArg.test.ts"] | ||
} |
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.
π