@storybook/react 10.6.0-alpha.0 → 10.6.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,1030 +1,7 @@
1
- import { ComponentType, JSX, ComponentProps } from 'react';
2
- import { WebRenderer, Canvas, Args, ComponentAnnotations, AnnotatedStoryFn, ArgsStoryFn, ArgsFromMeta, StoryAnnotations, StrictArgs, DecoratorFunction, LoaderFunction, StoryContext as StoryContext$1, ProjectAnnotations, NamedOrDefaultProjectAnnotations, NormalizedProjectAnnotations, StoryAnnotationsOrFn, ComposedStoryFn, Store_CSFExports, StoriesWithPartialProps, Renderer } from 'storybook/internal/types';
3
- export { ArgTypes, Args, Parameters, StrictArgs } from 'storybook/internal/types';
4
- import { RootOptions } from 'react-dom/client';
5
- import { PreviewAddon, InferTypes, AddonTypes, Preview as Preview$1, Meta as Meta$1, Story } from 'storybook/internal/csf';
6
-
7
- /**
8
- Convert a union type to an intersection type.
9
-
10
- Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
11
-
12
- @example
13
- ```
14
- import type {UnionToIntersection} from 'type-fest';
15
-
16
- type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
17
-
18
- type Intersection = UnionToIntersection<Union>;
19
- //=> {the(): void} & {great(arg: string): void} & {escape: boolean}
20
- ```
21
-
22
- @category Type
23
- */
24
- type UnionToIntersection<Union> = (
25
- // `extends unknown` is always going to be the case and is used to convert the
26
- // `Union` into a [distributive conditional
27
- // type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
28
- Union extends unknown
29
- // The union type is used as the only argument to a function since the union
30
- // of function arguments is an intersection.
31
- ? (distributedUnion: Union) => void
32
- // This won't happen.
33
- : never
34
- // Infer the `Intersection` type since TypeScript represents the positional
35
- // arguments of unions of functions as an intersection of the union.
36
- ) extends ((mergedIntersection: infer Intersection) => void)
37
- // The `& Union` is to ensure result of `UnionToIntersection<A | B>` is always assignable to `A | B`
38
- ? Intersection & Union
39
- : never;
40
-
41
- /**
42
- Create a union of all keys from a given type, even those exclusive to specific union members.
43
-
44
- Unlike the native `keyof` keyword, which returns keys present in **all** union members, this type returns keys from **any** member.
45
-
46
- @link https://stackoverflow.com/a/49402091
47
-
48
- @example
49
- ```
50
- import type {KeysOfUnion} from 'type-fest';
51
-
52
- type A = {
53
- common: string;
54
- a: number;
55
- };
56
-
57
- type B = {
58
- common: string;
59
- b: string;
60
- };
61
-
62
- type C = {
63
- common: string;
64
- c: boolean;
65
- };
66
-
67
- type Union = A | B | C;
68
-
69
- type CommonKeys = keyof Union;
70
- //=> 'common'
71
-
72
- type AllKeys = KeysOfUnion<Union>;
73
- //=> 'common' | 'a' | 'b' | 'c'
74
- ```
75
-
76
- @category Object
77
- */
78
- type KeysOfUnion<ObjectType> =
79
- // Hack to fix https://github.com/sindresorhus/type-fest/issues/1008
80
- keyof UnionToIntersection<ObjectType extends unknown ? Record<keyof ObjectType, never> : never>;
81
-
82
- /**
83
- Returns a boolean for whether the given type is `any`.
84
-
85
- @link https://stackoverflow.com/a/49928360/1490091
86
-
87
- Useful in type utilities, such as disallowing `any`s to be passed to a function.
88
-
89
- @example
90
- ```
91
- import type {IsAny} from 'type-fest';
92
-
93
- const typedObject = {a: 1, b: 2} as const;
94
- const anyObject: any = {a: 1, b: 2};
95
-
96
- function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(object: O, key: K) {
97
- return object[key];
98
- }
99
-
100
- const typedA = get(typedObject, 'a');
101
- //=> 1
102
-
103
- const anyA = get(anyObject, 'a');
104
- //=> any
105
- ```
106
-
107
- @category Type Guard
108
- @category Utilities
109
- */
110
- type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
111
-
112
- /**
113
- Returns a boolean for whether the given key is an optional key of type.
114
-
115
- This is useful when writing utility types or schema validators that need to differentiate `optional` keys.
116
-
117
- @example
118
- ```
119
- import type {IsOptionalKeyOf} from 'type-fest';
120
-
121
- type User = {
122
- name: string;
123
- surname: string;
124
-
125
- luckyNumber?: number;
126
- };
127
-
128
- type Admin = {
129
- name: string;
130
- surname?: string;
131
- };
132
-
133
- type T1 = IsOptionalKeyOf<User, 'luckyNumber'>;
134
- //=> true
135
-
136
- type T2 = IsOptionalKeyOf<User, 'name'>;
137
- //=> false
138
-
139
- type T3 = IsOptionalKeyOf<User, 'name' | 'luckyNumber'>;
140
- //=> boolean
141
-
142
- type T4 = IsOptionalKeyOf<User | Admin, 'name'>;
143
- //=> false
144
-
145
- type T5 = IsOptionalKeyOf<User | Admin, 'surname'>;
146
- //=> boolean
147
- ```
148
-
149
- @category Type Guard
150
- @category Utilities
151
- */
152
- type IsOptionalKeyOf<Type extends object, Key extends keyof Type> =
153
- IsAny<Type | Key> extends true ? never
154
- : Key extends keyof Type
155
- ? Type extends Record<Key, Type[Key]>
156
- ? false
157
- : true
158
- : false;
159
-
160
- /**
161
- Extract all optional keys from the given type.
162
-
163
- This is useful when you want to create a new type that contains different type values for the optional keys only.
164
-
165
- @example
166
- ```
167
- import type {OptionalKeysOf, Except} from 'type-fest';
168
-
169
- type User = {
170
- name: string;
171
- surname: string;
172
-
173
- luckyNumber?: number;
174
- };
175
-
176
- const REMOVE_FIELD = Symbol('remove field symbol');
177
- type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
178
- [Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
179
- };
180
-
181
- const update1: UpdateOperation<User> = {
182
- name: 'Alice',
183
- };
184
-
185
- const update2: UpdateOperation<User> = {
186
- name: 'Bob',
187
- luckyNumber: REMOVE_FIELD,
188
- };
189
- ```
190
-
191
- @category Utilities
192
- */
193
- type OptionalKeysOf<Type extends object> =
194
- Type extends unknown // For distributing `Type`
195
- ? (keyof {[Key in keyof Type as
196
- IsOptionalKeyOf<Type, Key> extends false
197
- ? never
198
- : Key
199
- ]: never
200
- }) & keyof Type // Intersect with `keyof Type` to ensure result of `OptionalKeysOf<Type>` is always assignable to `keyof Type`
201
- : never; // Should never happen
202
-
203
- /**
204
- Extract all required keys from the given type.
205
-
206
- This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...
207
-
208
- @example
209
- ```
210
- import type {RequiredKeysOf} from 'type-fest';
211
-
212
- declare function createValidation<
213
- Entity extends object,
214
- Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>,
215
- >(field: Key, validator: (value: Entity[Key]) => boolean): (entity: Entity) => boolean;
216
-
217
- type User = {
218
- name: string;
219
- surname: string;
220
- luckyNumber?: number;
221
- };
222
-
223
- const validator1 = createValidation<User>('name', value => value.length < 25);
224
- const validator2 = createValidation<User>('surname', value => value.length < 25);
225
-
226
- // @ts-expect-error
227
- const validator3 = createValidation<User>('luckyNumber', value => value > 0);
228
- // Error: Argument of type '"luckyNumber"' is not assignable to parameter of type '"name" | "surname"'.
229
- ```
230
-
231
- @category Utilities
232
- */
233
- type RequiredKeysOf<Type extends object> =
234
- Type extends unknown // For distributing `Type`
235
- ? Exclude<keyof Type, OptionalKeysOf<Type>>
236
- : never; // Should never happen
237
-
238
- /**
239
- Returns a boolean for whether the given type is `never`.
240
-
241
- @link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
242
- @link https://stackoverflow.com/a/53984913/10292952
243
- @link https://www.zhenghao.io/posts/ts-never
244
-
245
- Useful in type utilities, such as checking if something does not occur.
246
-
247
- @example
248
- ```
249
- import type {IsNever, And} from 'type-fest';
250
-
251
- type A = IsNever<never>;
252
- //=> true
253
-
254
- type B = IsNever<any>;
255
- //=> false
256
-
257
- type C = IsNever<unknown>;
258
- //=> false
259
-
260
- type D = IsNever<never[]>;
261
- //=> false
262
-
263
- type E = IsNever<object>;
264
- //=> false
265
-
266
- type F = IsNever<string>;
267
- //=> false
268
- ```
269
-
270
- @example
271
- ```
272
- import type {IsNever} from 'type-fest';
273
-
274
- type IsTrue<T> = T extends true ? true : false;
275
-
276
- // When a distributive conditional is instantiated with `never`, the entire conditional results in `never`.
277
- type A = IsTrue<never>;
278
- //=> never
279
-
280
- // If you don't want that behaviour, you can explicitly add an `IsNever` check before the distributive conditional.
281
- type IsTrueFixed<T> =
282
- IsNever<T> extends true ? false : T extends true ? true : false;
283
-
284
- type B = IsTrueFixed<never>;
285
- //=> false
286
- ```
287
-
288
- @category Type Guard
289
- @category Utilities
290
- */
291
- type IsNever<T> = [T] extends [never] ? true : false;
292
-
293
- /**
294
- An if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.
295
-
296
- Use-cases:
297
- - You can use this in combination with `Is*` types to create an if-else-like experience. For example, `If<IsAny<any>, 'is any', 'not any'>`.
298
-
299
- Note:
300
- - Returns a union of if branch and else branch if the given type is `boolean` or `any`. For example, `If<boolean, 'Y', 'N'>` will return `'Y' | 'N'`.
301
- - Returns the else branch if the given type is `never`. For example, `If<never, 'Y', 'N'>` will return `'N'`.
302
-
303
- @example
304
- ```
305
- import type {If} from 'type-fest';
306
-
307
- type A = If<true, 'yes', 'no'>;
308
- //=> 'yes'
309
-
310
- type B = If<false, 'yes', 'no'>;
311
- //=> 'no'
312
-
313
- type C = If<boolean, 'yes', 'no'>;
314
- //=> 'yes' | 'no'
315
-
316
- type D = If<any, 'yes', 'no'>;
317
- //=> 'yes' | 'no'
318
-
319
- type E = If<never, 'yes', 'no'>;
320
- //=> 'no'
321
- ```
322
-
323
- @example
324
- ```
325
- import type {If, IsAny, IsNever} from 'type-fest';
326
-
327
- type A = If<IsAny<unknown>, 'is any', 'not any'>;
328
- //=> 'not any'
329
-
330
- type B = If<IsNever<never>, 'is never', 'not never'>;
331
- //=> 'is never'
332
- ```
333
-
334
- @example
335
- ```
336
- import type {If, IsEqual} from 'type-fest';
337
-
338
- type IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;
339
-
340
- type A = IfEqual<string, string, 'equal', 'not equal'>;
341
- //=> 'equal'
342
-
343
- type B = IfEqual<string, number, 'equal', 'not equal'>;
344
- //=> 'not equal'
345
- ```
346
-
347
- Note: Sometimes using the `If` type can make an implementation non–tail-recursive, which can impact performance. In such cases, it’s better to use a conditional directly. Refer to the following example:
348
-
349
- @example
350
- ```
351
- import type {If, IsEqual, StringRepeat} from 'type-fest';
352
-
353
- type HundredZeroes = StringRepeat<'0', 100>;
354
-
355
- // The following implementation is not tail recursive
356
- type Includes<S extends string, Char extends string> =
357
- S extends `${infer First}${infer Rest}`
358
- ? If<IsEqual<First, Char>,
359
- 'found',
360
- Includes<Rest, Char>>
361
- : 'not found';
362
-
363
- // Hence, instantiations with long strings will fail
364
- // @ts-expect-error
365
- type Fails = Includes<HundredZeroes, '1'>;
366
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
367
- // Error: Type instantiation is excessively deep and possibly infinite.
368
-
369
- // However, if we use a simple conditional instead of `If`, the implementation becomes tail-recursive
370
- type IncludesWithoutIf<S extends string, Char extends string> =
371
- S extends `${infer First}${infer Rest}`
372
- ? IsEqual<First, Char> extends true
373
- ? 'found'
374
- : IncludesWithoutIf<Rest, Char>
375
- : 'not found';
376
-
377
- // Now, instantiations with long strings will work
378
- type Works = IncludesWithoutIf<HundredZeroes, '1'>;
379
- //=> 'not found'
380
- ```
381
-
382
- @category Type Guard
383
- @category Utilities
384
- */
385
- type If<Type extends boolean, IfBranch, ElseBranch> =
386
- IsNever<Type> extends true
387
- ? ElseBranch
388
- : Type extends true
389
- ? IfBranch
390
- : ElseBranch;
391
-
392
- /**
393
- Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
394
-
395
- @example
396
- ```
397
- import type {Simplify} from 'type-fest';
398
-
399
- type PositionProps = {
400
- top: number;
401
- left: number;
402
- };
403
-
404
- type SizeProps = {
405
- width: number;
406
- height: number;
407
- };
408
-
409
- // In your editor, hovering over `Props` will show a flattened object with all the properties.
410
- type Props = Simplify<PositionProps & SizeProps>;
411
- ```
412
-
413
- Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
414
-
415
- If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
416
-
417
- @example
418
- ```
419
- import type {Simplify} from 'type-fest';
420
-
421
- interface SomeInterface {
422
- foo: number;
423
- bar?: string;
424
- baz: number | undefined;
425
- }
426
-
427
- type SomeType = {
428
- foo: number;
429
- bar?: string;
430
- baz: number | undefined;
431
- };
432
-
433
- const literal = {foo: 123, bar: 'hello', baz: 456};
434
- const someType: SomeType = literal;
435
- const someInterface: SomeInterface = literal;
436
-
437
- declare function fn(object: Record<string, unknown>): void;
438
-
439
- fn(literal); // Good: literal object type is sealed
440
- fn(someType); // Good: type is sealed
441
- // @ts-expect-error
442
- fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
443
- fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
444
- ```
445
-
446
- @link https://github.com/microsoft/TypeScript/issues/15300
447
- @see {@link SimplifyDeep}
448
- @category Object
449
- */
450
- type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};
451
-
452
- /**
453
- Returns a boolean for whether the two given types are equal.
454
-
455
- @link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
456
- @link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
457
-
458
- Use-cases:
459
- - If you want to make a conditional branch based on the result of a comparison of two types.
460
-
461
- @example
462
- ```
463
- import type {IsEqual} from 'type-fest';
464
-
465
- // This type returns a boolean for whether the given array includes the given item.
466
- // `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
467
- type Includes<Value extends readonly any[], Item> =
468
- Value extends readonly [Value[0], ...infer rest]
469
- ? IsEqual<Value[0], Item> extends true
470
- ? true
471
- : Includes<rest, Item>
472
- : false;
473
- ```
474
-
475
- @category Type Guard
476
- @category Utilities
477
- */
478
- type IsEqual<A, B> =
479
- [A] extends [B]
480
- ? [B] extends [A]
481
- ? _IsEqual<A, B>
482
- : false
483
- : false;
484
-
485
- // This version fails the `equalWrappedTupleIntersectionToBeNeverAndNeverExpanded` test in `test-d/is-equal.ts`.
486
- type _IsEqual<A, B> =
487
- (<G>() => G extends A & G | G ? 1 : 2) extends
488
- (<G>() => G extends B & G | G ? 1 : 2)
489
- ? true
490
- : false;
491
-
492
- /**
493
- Omit any index signatures from the given object type, leaving only explicitly defined properties.
494
-
495
- This is the counterpart of `PickIndexSignature`.
496
-
497
- Use-cases:
498
- - Remove overly permissive signatures from third-party types.
499
-
500
- This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
501
-
502
- It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
503
-
504
- (The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
505
-
506
- ```
507
- const indexed: Record<string, unknown> = {}; // Allowed
508
-
509
- // @ts-expect-error
510
- const keyed: Record<'foo', unknown> = {}; // Error
511
- // TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
512
- ```
513
-
514
- Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
515
-
516
- ```
517
- type Indexed = {} extends Record<string, unknown>
518
- ? '✅ `{}` is assignable to `Record<string, unknown>`'
519
- : '❌ `{}` is NOT assignable to `Record<string, unknown>`';
520
-
521
- type IndexedResult = Indexed;
522
- //=> '✅ `{}` is assignable to `Record<string, unknown>`'
523
-
524
- type Keyed = {} extends Record<'foo' | 'bar', unknown>
525
- ? '✅ `{}` is assignable to `Record<\'foo\' | \'bar\', unknown>`'
526
- : '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`';
527
-
528
- type KeyedResult = Keyed;
529
- //=> '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`'
530
- ```
531
-
532
- Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
533
-
534
- ```
535
- type OmitIndexSignature<ObjectType> = {
536
- [KeyType in keyof ObjectType // Map each key of `ObjectType`...
537
- ]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
538
- };
539
- ```
540
-
541
- ...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
542
-
543
- ```
544
- type OmitIndexSignature<ObjectType> = {
545
- [KeyType in keyof ObjectType
546
- // Is `{}` assignable to `Record<KeyType, unknown>`?
547
- as {} extends Record<KeyType, unknown>
548
- ? never // ✅ `{}` is assignable to `Record<KeyType, unknown>`
549
- : KeyType // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
550
- ]: ObjectType[KeyType];
551
- };
552
- ```
553
-
554
- If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
555
-
556
- @example
557
- ```
558
- import type {OmitIndexSignature} from 'type-fest';
559
-
560
- type Example = {
561
- // These index signatures will be removed.
562
- [x: string]: any;
563
- [x: number]: any;
564
- [x: symbol]: any;
565
- [x: `head-${string}`]: string;
566
- [x: `${string}-tail`]: string;
567
- [x: `head-${string}-tail`]: string;
568
- [x: `${bigint}`]: string;
569
- [x: `embedded-${number}`]: string;
570
-
571
- // These explicitly defined keys will remain.
572
- foo: 'bar';
573
- qux?: 'baz';
574
- };
575
-
576
- type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
577
- //=> {foo: 'bar'; qux?: 'baz'}
578
- ```
579
-
580
- @see {@link PickIndexSignature}
581
- @category Object
582
- */
583
- type OmitIndexSignature<ObjectType> = {
584
- [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
585
- ? never
586
- : KeyType]: ObjectType[KeyType];
587
- };
588
-
589
- /**
590
- Pick only index signatures from the given object type, leaving out all explicitly defined properties.
591
-
592
- This is the counterpart of `OmitIndexSignature`.
593
-
594
- @example
595
- ```
596
- import type {PickIndexSignature} from 'type-fest';
597
-
598
- declare const symbolKey: unique symbol;
599
-
600
- type Example = {
601
- // These index signatures will remain.
602
- [x: string]: unknown;
603
- [x: number]: unknown;
604
- [x: symbol]: unknown;
605
- [x: `head-${string}`]: string;
606
- [x: `${string}-tail`]: string;
607
- [x: `head-${string}-tail`]: string;
608
- [x: `${bigint}`]: string;
609
- [x: `embedded-${number}`]: string;
610
-
611
- // These explicitly defined keys will be removed.
612
- ['kebab-case-key']: string;
613
- [symbolKey]: string;
614
- foo: 'bar';
615
- qux?: 'baz';
616
- };
617
-
618
- type ExampleIndexSignature = PickIndexSignature<Example>;
619
- // {
620
- // [x: string]: unknown;
621
- // [x: number]: unknown;
622
- // [x: symbol]: unknown;
623
- // [x: `head-${string}`]: string;
624
- // [x: `${string}-tail`]: string;
625
- // [x: `head-${string}-tail`]: string;
626
- // [x: `${bigint}`]: string;
627
- // [x: `embedded-${number}`]: string;
628
- // }
629
- ```
630
-
631
- @see {@link OmitIndexSignature}
632
- @category Object
633
- */
634
- type PickIndexSignature<ObjectType> = {
635
- [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
636
- ? KeyType
637
- : never]: ObjectType[KeyType];
638
- };
639
-
640
- // Merges two objects without worrying about index signatures.
641
- type SimpleMerge<Destination, Source> = Simplify<{
642
- [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key];
643
- } & Source>;
644
-
645
- /**
646
- Merge two types into a new type. Keys of the second type overrides keys of the first type.
647
-
648
- This is different from the TypeScript `&` (intersection) operator. With `&`, conflicting property types are intersected, which often results in `never`. For example, `{a: string} & {a: number}` makes `a` become `string & number`, which resolves to `never`. With `Merge`, the second type's keys cleanly override the first, so `Merge<{a: string}, {a: number}>` gives `{a: number}` as expected. `Merge` also produces a flattened type (via `Simplify`), making it more readable in IDE tooltips compared to `A & B`.
649
-
650
- @example
651
- ```
652
- import type {Merge} from 'type-fest';
653
-
654
- type Foo = {
655
- a: string;
656
- b: number;
657
- };
658
-
659
- type Bar = {
660
- a: number; // Conflicts with Foo['a']
661
- c: boolean;
662
- };
663
-
664
- // With `&`, `a` becomes `string & number` which is `never`. Not what you want.
665
- type WithIntersection = (Foo & Bar)['a'];
666
- //=> never
667
-
668
- // With `Merge`, `a` is cleanly overridden to `number`.
669
- type WithMerge = Merge<Foo, Bar>['a'];
670
- //=> number
671
- ```
672
-
673
- @example
674
- ```
675
- import type {Merge} from 'type-fest';
676
-
677
- type Foo = {
678
- [x: string]: unknown;
679
- [x: number]: unknown;
680
- foo: string;
681
- bar: symbol;
682
- };
683
-
684
- type Bar = {
685
- [x: number]: number;
686
- [x: symbol]: unknown;
687
- bar: Date;
688
- baz: boolean;
689
- };
690
-
691
- export type FooBar = Merge<Foo, Bar>;
692
- //=> {
693
- // [x: string]: unknown;
694
- // [x: number]: number;
695
- // [x: symbol]: unknown;
696
- // foo: string;
697
- // bar: Date;
698
- // baz: boolean;
699
- // }
700
- ```
701
-
702
- Note: If you want a merge type that more accurately reflects the runtime behavior of object spread or `Object.assign`, refer to the {@link ObjectMerge} type.
703
-
704
- @see {@link ObjectMerge}
705
- @category Object
706
- */
707
- type Merge<Destination, Source> =
708
- Destination extends unknown // For distributing `Destination`
709
- ? Source extends unknown // For distributing `Source`
710
- ? If<IsEqual<Destination, Source>, Destination, _Merge<Destination, Source>>
711
- : never // Should never happen
712
- : never; // Should never happen
713
-
714
- type _Merge<Destination, Source> =
715
- Simplify<
716
- SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>>
717
- & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>
718
- >;
719
-
720
- /**
721
- Works similar to the built-in `Pick` utility type, except for the following differences:
722
- - Distributes over union types and allows picking keys from any member of the union type.
723
- - Primitives types are returned as-is.
724
- - Picks all keys if `Keys` is `any`.
725
- - Doesn't pick `number` from a `string` index signature.
726
-
727
- @example
728
- ```
729
- type ImageUpload = {
730
- url: string;
731
- size: number;
732
- thumbnailUrl: string;
733
- };
734
-
735
- type VideoUpload = {
736
- url: string;
737
- duration: number;
738
- encodingFormat: string;
739
- };
740
-
741
- // Distributes over union types and allows picking keys from any member of the union type
742
- type MediaDisplay = HomomorphicPick<ImageUpload | VideoUpload, "url" | "size" | "duration">;
743
- //=> {url: string; size: number} | {url: string; duration: number}
744
-
745
- // Primitive types are returned as-is
746
- type Primitive = HomomorphicPick<string | number, 'toUpperCase' | 'toString'>;
747
- //=> string | number
748
-
749
- // Picks all keys if `Keys` is `any`
750
- type Any = HomomorphicPick<{a: 1; b: 2} | {c: 3}, any>;
751
- //=> {a: 1; b: 2} | {c: 3}
752
-
753
- // Doesn't pick `number` from a `string` index signature
754
- type IndexSignature = HomomorphicPick<{[k: string]: unknown}, number>;
755
- //=> {}
756
- */
757
- type HomomorphicPick<T, Keys extends KeysOfUnion<T>> = {
758
- [P in keyof T as Extract<P, Keys>]: T[P]
759
- };
760
-
761
- /**
762
- Merges user specified options with default options.
763
-
764
- @example
765
- ```
766
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
767
- type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
768
- type SpecifiedOptions = {leavesOnly: true};
769
-
770
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
771
- //=> {maxRecursionDepth: 10; leavesOnly: true}
772
- ```
773
-
774
- @example
775
- ```
776
- // Complains if default values are not provided for optional options
777
-
778
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
779
- type DefaultPathsOptions = {maxRecursionDepth: 10};
780
- type SpecifiedOptions = {};
781
-
782
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
783
- // ~~~~~~~~~~~~~~~~~~~
784
- // Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
785
- ```
786
-
787
- @example
788
- ```
789
- // Complains if an option's default type does not conform to the expected type
790
-
791
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
792
- type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
793
- type SpecifiedOptions = {};
794
-
795
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
796
- // ~~~~~~~~~~~~~~~~~~~
797
- // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
798
- ```
799
-
800
- @example
801
- ```
802
- // Complains if an option's specified type does not conform to the expected type
803
-
804
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
805
- type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
806
- type SpecifiedOptions = {leavesOnly: 'yes'};
807
-
808
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
809
- // ~~~~~~~~~~~~~~~~
810
- // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
811
- ```
812
- */
813
- type ApplyDefaultOptions<
814
- Options extends object,
815
- Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>,
816
- SpecifiedOptions extends Options,
817
- > =
818
- If<IsAny<SpecifiedOptions>, Defaults,
819
- If<IsNever<SpecifiedOptions>, Defaults,
820
- Simplify<Merge<Defaults, {
821
- [Key in keyof SpecifiedOptions
822
- as Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key
823
- ]: SpecifiedOptions[Key]
824
- }> & Required<Options>>>>;
825
-
826
- /**
827
- Filter out keys from an object.
828
-
829
- Returns `never` if `Exclude` is strictly equal to `Key`.
830
- Returns `never` if `Key` extends `Exclude`.
831
- Returns `Key` otherwise.
832
-
833
- @example
834
- ```
835
- type Filtered = Filter<'foo', 'foo'>;
836
- //=> never
837
- ```
838
-
839
- @example
840
- ```
841
- type Filtered = Filter<'bar', string>;
842
- //=> never
843
- ```
844
-
845
- @example
846
- ```
847
- type Filtered = Filter<'bar', 'foo'>;
848
- //=> 'bar'
849
- ```
850
-
851
- @see {Except}
852
- */
853
- type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
854
-
855
- type ExceptOptions = {
856
- /**
857
- Disallow assigning non-specified properties.
858
-
859
- Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
860
-
861
- @default false
862
- */
863
- requireExactProps?: boolean;
864
- };
865
-
866
- type DefaultExceptOptions = {
867
- requireExactProps: false;
868
- };
869
-
870
- /**
871
- Create a type from an object type without certain keys.
872
-
873
- We recommend setting the `requireExactProps` option to `true`.
874
-
875
- This type is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type). The `Omit` type does not restrict the omitted keys to be keys present on the given type, while `Except` does. The benefits of a stricter type are avoiding typos and allowing the compiler to pick up on rename refactors automatically.
876
-
877
- This type was proposed to the TypeScript team, which declined it, saying they prefer that libraries implement stricter versions of the built-in types ([microsoft/TypeScript#30825](https://github.com/microsoft/TypeScript/issues/30825#issuecomment-523668235)).
878
-
879
- @example
880
- ```
881
- import type {Except} from 'type-fest';
882
-
883
- type Foo = {
884
- a: number;
885
- b: string;
886
- };
887
-
888
- type FooWithoutA = Except<Foo, 'a'>;
889
- //=> {b: string}
890
-
891
- // @ts-expect-error
892
- const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
893
- // errors: 'a' does not exist in type '{ b: string; }'
894
-
895
- type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
896
- //=> {a: number} & Partial<Record<'b', never>>
897
-
898
- // @ts-expect-error
899
- const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
900
- // errors at 'b': Type 'string' is not assignable to type 'undefined'.
901
-
902
- // The `Omit` utility type doesn't work when omitting specific keys from objects containing index signatures.
903
-
904
- // Consider the following example:
905
-
906
- type UserData = {
907
- [metadata: string]: string;
908
- email: string;
909
- name: string;
910
- role: 'admin' | 'user';
911
- };
912
-
913
- // `Omit` clearly doesn't behave as expected in this case:
914
- type PostPayload = Omit<UserData, 'email'>;
915
- //=> {[x: string]: string; [x: number]: string}
916
-
917
- // In situations like this, `Except` works better.
918
- // It simply removes the `email` key while preserving all the other keys.
919
- type PostPayloadFixed = Except<UserData, 'email'>;
920
- //=> {[x: string]: string; name: string; role: 'admin' | 'user'}
921
- ```
922
-
923
- @category Object
924
- */
925
- type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> =
926
- _Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;
927
-
928
- type _Except<ObjectType, KeysType extends keyof ObjectType, Options extends Required<ExceptOptions>> = {
929
- [KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];
930
- } & (Options['requireExactProps'] extends true
931
- ? Partial<Record<KeysType, never>>
932
- : {});
933
-
934
- /**
935
- Create a type that makes the given keys optional, while keeping the remaining keys as is.
936
-
937
- Use-case: You want to define a single model where the only thing that changes is whether or not some of the keys are optional.
938
-
939
- @example
940
- ```
941
- import type {SetOptional} from 'type-fest';
942
-
943
- type Foo = {
944
- a: number;
945
- b?: string;
946
- c: boolean;
947
- };
948
-
949
- type SomeOptional = SetOptional<Foo, 'b' | 'c'>;
950
- //=> {a: number; b?: string; c?: boolean}
951
- ```
952
-
953
- @category Object
954
- */
955
- type SetOptional<BaseType, Keys extends keyof BaseType> =
956
- (BaseType extends (...arguments_: never) => any
957
- ? (...arguments_: Parameters<BaseType>) => ReturnType<BaseType>
958
- : unknown)
959
- & _SetOptional<BaseType, Keys>;
960
-
961
- type _SetOptional<BaseType, Keys extends keyof BaseType> =
962
- BaseType extends unknown // To distribute `BaseType` when it's a union type.
963
- ? Simplify<
964
- // Pick just the keys that are readonly from the base type.
965
- Except<BaseType, Keys>
966
- // Pick the keys that should be mutable from the base type and make them mutable.
967
- & Partial<HomomorphicPick<BaseType, Keys>>
968
- >
969
- : never;
970
-
971
- interface ReactRenderer extends WebRenderer {
972
- component: ComponentType<this['T']>;
973
- storyResult: StoryFnReactReturnType;
974
- mount: (ui?: JSX.Element) => Promise<Canvas>;
975
- }
976
- interface ReactParameters {
977
- /** React renderer configuration */
978
- react?: {
979
- /**
980
- * Whether to enable React Server Components
981
- *
982
- * @see https://storybook.js.org/docs/get-started/frameworks/nextjs#react-server-components-rsc
983
- */
984
- rsc?: boolean;
985
- /** Options passed to React root creation */
986
- rootOptions?: RootOptions;
987
- };
988
- }
989
- interface ReactTypes extends ReactRenderer {
990
- parameters: ReactParameters;
991
- }
992
- type StoryFnReactReturnType = JSX.Element;
993
-
994
- /**
995
- * Metadata to configure the stories for a component.
996
- *
997
- * @see [Default export](https://storybook.js.org/docs/api/csf#default-export)
998
- */
999
- type Meta<TCmpOrArgs = Args> = [TCmpOrArgs] extends [ComponentType<any>] ? ComponentAnnotations<ReactRenderer, ComponentProps<TCmpOrArgs>> : ComponentAnnotations<ReactRenderer, TCmpOrArgs>;
1000
- /**
1001
- * Story function that represents a CSFv2 component example.
1002
- *
1003
- * @see [Named Story exports](https://storybook.js.org/docs/api/csf#named-story-exports)
1004
- */
1005
- type StoryFn<TCmpOrArgs = Args> = [TCmpOrArgs] extends [ComponentType<any>] ? AnnotatedStoryFn<ReactRenderer, ComponentProps<TCmpOrArgs>> : AnnotatedStoryFn<ReactRenderer, TCmpOrArgs>;
1006
- /**
1007
- * Story object that represents a CSFv3 component example.
1008
- *
1009
- * @see [Named Story exports](https://storybook.js.org/docs/api/csf#named-story-exports)
1010
- */
1011
- type StoryObj<TMetaOrCmpOrArgs = Args> = [TMetaOrCmpOrArgs] extends [
1012
- {
1013
- render?: ArgsStoryFn<ReactRenderer, any>;
1014
- component?: infer Component;
1015
- args?: infer DefaultArgs;
1016
- }
1017
- ] ? Simplify<(Component extends ComponentType<any> ? ComponentProps<Component> : unknown) & ArgsFromMeta<ReactRenderer, TMetaOrCmpOrArgs>> extends infer TArgs ? StoryAnnotations<ReactRenderer, AddMocks<TArgs, DefaultArgs>, SetOptional<TArgs, keyof TArgs & keyof DefaultArgs>> : never : TMetaOrCmpOrArgs extends ComponentType<any> ? StoryAnnotations<ReactRenderer, ComponentProps<TMetaOrCmpOrArgs>> : StoryAnnotations<ReactRenderer, TMetaOrCmpOrArgs>;
1018
- type AddMocks<TArgs, DefaultArgs> = Simplify<{
1019
- [T in keyof TArgs]: T extends keyof DefaultArgs ? DefaultArgs[T] extends (...args: any) => any & {
1020
- mock: {};
1021
- } ? DefaultArgs[T] : TArgs[T] : TArgs[T];
1022
- }>;
1023
- type Decorator<TArgs = StrictArgs> = DecoratorFunction<ReactRenderer, TArgs>;
1024
- type Loader<TArgs = StrictArgs> = LoaderFunction<ReactRenderer, TArgs>;
1025
- type StoryContext<TArgs = StrictArgs> = StoryContext$1<ReactRenderer, TArgs>;
1026
- type Preview = ProjectAnnotations<ReactRenderer>;
1
+ import { _ as ReactRenderer, a as AddMocks, c as Decorator, d as Parameters, f as Preview, g as StrictArgs, h as StoryObj, i as __definePreview, l as Loader, m as StoryFn, n as ReactPreview, o as ArgTypes, p as StoryContext, r as ReactStory, s as Args, t as ReactMeta, u as Meta, v as ReactTypes } from "./chunk-ojHmM-yX.js";
2
+ import { Args as Args$1, ComposedStoryFn, NamedOrDefaultProjectAnnotations, NormalizedProjectAnnotations, ProjectAnnotations, Store_CSFExports, StoriesWithPartialProps, StoryAnnotationsOrFn } from "storybook/internal/types";
1027
3
 
4
+ //#region code/renderers/react/.dts-emit/code/renderers/react/src/portable-stories.d.ts
1028
5
  /**
1029
6
  * Function that sets the globalConfig of your storybook. The global config is the preview module of
1030
7
  * your .storybook folder.
@@ -1075,7 +52,7 @@ declare const INTERNAL_DEFAULT_PROJECT_ANNOTATIONS: ProjectAnnotations<ReactRend
1075
52
  * this can be applied automatically if you use `setProjectAnnotations` in your setup files.
1076
53
  * @param [exportsName] - In case your story does not contain a name and you want it to have a name.
1077
54
  */
1078
- declare function composeStory<TArgs extends Args = Args>(story: StoryAnnotationsOrFn<ReactRenderer, TArgs>, componentAnnotations: Meta<TArgs | any>, projectAnnotations?: ProjectAnnotations<ReactRenderer>, exportsName?: string): ComposedStoryFn<ReactRenderer, Partial<TArgs>>;
55
+ declare function composeStory<TArgs extends Args$1 = Args$1>(story: StoryAnnotationsOrFn<ReactRenderer, TArgs>, componentAnnotations: Meta<TArgs | any>, projectAnnotations?: ProjectAnnotations<ReactRenderer>, exportsName?: string): ComposedStoryFn<ReactRenderer, Partial<TArgs>>;
1079
56
  /**
1080
57
  * Function that will receive a stories import (e.g. `import * as stories from './Button.stories'`)
1081
58
  * and optionally projectAnnotations (e.g. `import * as projectAnnotations from
@@ -1104,160 +81,5 @@ declare function composeStory<TArgs extends Args = Args>(story: StoryAnnotations
1104
81
  * this can be applied automatically if you use `setProjectAnnotations` in your setup files.
1105
82
  */
1106
83
  declare function composeStories<TModule extends Store_CSFExports<ReactRenderer, any>>(csfExports: TModule, projectAnnotations?: ProjectAnnotations<ReactRenderer>): Omit<StoriesWithPartialProps<ReactRenderer, TModule>, keyof Store_CSFExports>;
1107
-
1108
- /** Extracts and unions all args types from an array of decorators. */
1109
- type DecoratorsArgs<TRenderer extends Renderer, Decorators> = UnionToIntersection<Decorators extends DecoratorFunction<TRenderer, infer TArgs> ? TArgs : unknown>;
1110
- type InferArgs<TArgs, T, Decorators> = Simplify<TArgs & Simplify<OmitIndexSignature<DecoratorsArgs<ReactTypes & T, Decorators>>>>;
1111
- type InferReactTypes<T, TArgs, Decorators> = ReactTypes & T & {
1112
- args: Simplify<InferArgs<TArgs, T, Decorators>>;
1113
- };
1114
- /**
1115
- * Creates a React-specific preview configuration with CSF factories support.
1116
- *
1117
- * This function wraps the base `definePreview` and adds React-specific annotations for rendering
1118
- * and documentation. It returns a `ReactPreview` that provides type-safe `meta()` and `story()`
1119
- * factory methods.
1120
- *
1121
- * @example
1122
- *
1123
- * ```ts
1124
- * // .storybook/preview.ts
1125
- * import { definePreview } from '@storybook/react';
1126
- *
1127
- * export const preview = definePreview({
1128
- * addons: [],
1129
- * parameters: { layout: 'centered' },
1130
- * });
1131
- * ```
1132
- */
1133
- declare function __definePreview<Addons extends PreviewAddon<never>[]>(input: {
1134
- addons: Addons;
1135
- } & ProjectAnnotations<ReactTypes & InferTypes<Addons>>): ReactPreview<ReactTypes & InferTypes<Addons>>;
1136
- /**
1137
- * React-specific Preview interface that provides type-safe CSF factory methods.
1138
- *
1139
- * Use `preview.meta()` to create a meta configuration for a component, and then `meta.story()` to
1140
- * create individual stories. The type system will infer args from the component props, decorators,
1141
- * and any addon types.
1142
- *
1143
- * @example
1144
- *
1145
- * ```ts
1146
- * const meta = preview.meta({ component: Button });
1147
- * export const Primary = meta.story({ args: { label: 'Click me' } });
1148
- * ```
1149
- */
1150
- /** @ts-expect-error We cannot implement the meta faithfully here, but that is okay. */
1151
- interface ReactPreview<T extends AddonTypes> extends Preview$1<ReactTypes & T> {
1152
- /**
1153
- * Narrows the type of the preview to include additional type information. This is useful when you
1154
- * need to add args that aren't inferred from the component.
1155
- *
1156
- * @example
1157
- *
1158
- * ```ts
1159
- * const meta = preview.type<{ args: { theme: 'light' | 'dark' } }>().meta({
1160
- * component: Button,
1161
- * });
1162
- * ```
1163
- */
1164
- type<R>(): ReactPreview<T & R>;
1165
- meta<TArgs extends Args, Decorators extends DecoratorFunction<ReactTypes & T, any>, TMetaArgs extends Partial<TArgs & T['args']>>(meta: {
1166
- render?: ArgsStoryFn<ReactTypes & T, TArgs & T['args']>;
1167
- component?: ComponentType<TArgs>;
1168
- decorators?: Decorators | Decorators[];
1169
- args?: TMetaArgs;
1170
- } & Omit<ComponentAnnotations<ReactTypes & T, TArgs>, 'decorators' | 'component' | 'args' | 'render'>): ReactMeta<InferReactTypes<T, TArgs, Decorators>, Omit<ComponentAnnotations<InferReactTypes<T, TArgs, Decorators>>, 'args'> & {
1171
- args: Partial<TArgs> extends TMetaArgs ? {} : TMetaArgs;
1172
- }>;
1173
- }
1174
- /**
1175
- * React-specific Meta interface returned by `preview.meta()`.
1176
- *
1177
- * Provides the `story()` method to create individual stories with proper type inference. Args
1178
- * provided in meta become optional in stories, while missing required args must be provided at the
1179
- * story level.
1180
- */
1181
- interface ReactMeta<T extends ReactTypes, MetaInput extends ComponentAnnotations<T>>
1182
- /** @ts-expect-error ReactMeta requires two type parameters, but Meta's constraints differ */
1183
- extends Meta$1<T, MetaInput> {
1184
- /**
1185
- * Creates a story with a custom render function that takes no args.
1186
- *
1187
- * This overload allows you to define a story using just a render function or an object with a
1188
- * render function that doesn't depend on args. Since the render function doesn't use args, no
1189
- * args need to be provided regardless of what's required by the component.
1190
- *
1191
- * @example
1192
- *
1193
- * ```ts
1194
- * // Using just a render function
1195
- * export const CustomRender = meta.story(() => <div>Custom content</div>);
1196
- *
1197
- * // Using an object with render
1198
- * export const WithRender = meta.story({
1199
- * render: () => <MyComponent prop="static" />,
1200
- * });
1201
- * ```
1202
- */
1203
- story<TInput extends (() => ReactTypes['storyResult']) | (StoryAnnotations<T, T['args']> & {
1204
- render: () => ReactTypes['storyResult'];
1205
- })>(story: TInput): ReactStory<T, TInput extends () => ReactTypes['storyResult'] ? {
1206
- render: TInput;
1207
- } : TInput>;
1208
- /**
1209
- * Creates a story with custom configuration including args, decorators, or other annotations.
1210
- *
1211
- * This is the primary overload for defining stories. Args that were already provided in meta
1212
- * become optional, while any remaining required args must be specified here.
1213
- *
1214
- * @example
1215
- *
1216
- * ```ts
1217
- * // Provide required args not in meta
1218
- * export const Primary = meta.story({
1219
- * args: { label: 'Click me', disabled: false },
1220
- * });
1221
- *
1222
- * // Override meta args and add story-specific configuration
1223
- * export const Disabled = meta.story({
1224
- * args: { disabled: true },
1225
- * decorators: [withCustomWrapper],
1226
- * });
1227
- * ```
1228
- */
1229
- story<TInput extends Simplify<StoryAnnotations<T, AddMocks<T['args'], MetaInput['args']>, SetOptional<T['args'], keyof T['args'] & keyof MetaInput['args']>>>>(story: TInput
1230
- /** @ts-expect-error hard */
1231
- ): ReactStory<T, TInput>;
1232
- /**
1233
- * Creates a story with no additional configuration.
1234
- *
1235
- * This overload is only available when all required args have been provided in meta. The
1236
- * conditional type `Partial<T['args']> extends SetOptional<...>` checks if the remaining required
1237
- * args (after accounting for args provided in meta) are all optional. If so, the function accepts
1238
- * zero arguments `[]`. Otherwise, it requires `[never]` which makes this overload unmatchable,
1239
- * forcing the user to provide args.
1240
- *
1241
- * @example
1242
- *
1243
- * ```ts
1244
- * // When meta provides all required args, story() can be called with no arguments
1245
- * const meta = preview.meta({ component: Button, args: { label: 'Hi', disabled: false } });
1246
- * export const Default = meta.story(); // Valid - all args provided in meta
1247
- * ```
1248
- */
1249
- story(..._args: Partial<T['args']> extends SetOptional<T['args'], keyof T['args'] & keyof MetaInput['args']> ? [] : [never]): ReactStory<T, {}>;
1250
- }
1251
- /**
1252
- * React-specific Story interface returned by `meta.story()`.
1253
- *
1254
- * Represents a single story with its configuration and provides access to the composed story for
1255
- * testing via `story.run()`.
1256
- *
1257
- * Also includes a `Component` property for portable story compatibility.
1258
- */
1259
- interface ReactStory<T extends ReactTypes, TInput extends StoryAnnotations<T, T['args']>> extends Story<T, TInput> {
1260
- Component: ComponentType<Partial<T['args']>>;
1261
- }
1262
-
1263
- export { type AddMocks, type Decorator, INTERNAL_DEFAULT_PROJECT_ANNOTATIONS, type Loader, type Meta, type Preview, type ReactMeta, type ReactPreview, type ReactRenderer, type ReactStory, type ReactTypes, type StoryContext, type StoryFn, type StoryObj, __definePreview, composeStories, composeStory, setProjectAnnotations };
84
+ //#endregion
85
+ export { AddMocks, type ArgTypes, type Args, Decorator, INTERNAL_DEFAULT_PROJECT_ANNOTATIONS, Loader, Meta, type Parameters, Preview, ReactMeta, ReactPreview, type ReactRenderer, ReactStory, type ReactTypes, StoryContext, StoryFn, StoryObj, type StrictArgs, __definePreview, composeStories, composeStory, setProjectAnnotations };