Skip to content

story.ts: improve Conditional typing #31546

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

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions code/core/src/csf/story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ type ControlType =
| 'text';

type ConditionalTest = { truthy?: boolean } | { exists: boolean } | { eq: any } | { neq: any };
type ConditionalValue = { arg: string } | { global: string };
export type Conditional = ConditionalValue & ConditionalTest;
type ConditionalValue<TArgs = Args> = { arg: keyof TArgs } | { global: string };
export type Conditional<TArgs = Args> = ConditionalValue<TArgs> & ConditionalTest;

interface ControlBase {
[key: string]: any;
Expand Down Expand Up @@ -106,13 +106,13 @@ type Control =
}
));

export interface InputType {
export interface InputType<TArgs = Args> {
/** @see https://storybook.js.org/docs/api/arg-types#control */
control?: Control;
/** @see https://storybook.js.org/docs/api/arg-types#description */
description?: string;
/** @see https://storybook.js.org/docs/api/arg-types#if */
if?: Conditional;
if?: Conditional<TArgs>;
/** @see https://storybook.js.org/docs/api/arg-types#mapping */
mapping?: { [key: string]: any };
/** @see https://storybook.js.org/docs/api/arg-types#name */
Expand Down Expand Up @@ -157,7 +157,7 @@ export interface StrictArgs {
}

/** @see https://storybook.js.org/docs/api/arg-types#argtypes */
export type ArgTypes<TArgs = Args> = { [name in keyof TArgs]: InputType };
export type ArgTypes<TArgs = Args> = { [name in keyof TArgs]: InputType<TArgs> };
export type StrictArgTypes<TArgs = Args> = { [name in keyof TArgs]: StrictInputType };

export interface Globals {
Expand Down
Loading