import { ComponentType, ComponentProps } from 'react'; import { Args, ComponentAnnotations, AnnotatedStoryFn, ArgsStoryFn, ArgsFromMeta, StoryAnnotations, StrictArgs, DecoratorFunction, LoaderFunction, StoryContext as StoryContext$1, ProjectAnnotations } from 'storybook/internal/types'; import { R as ReactRenderer } from './types-a5624094.js'; declare global { interface SymbolConstructor { readonly observable: symbol; } } /** Returns a boolean for whether the two given types are equal. @link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650 @link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796 */ type IsEqual = (() => G extends T ? 1 : 2) extends (() => G extends U ? 1 : 2) ? true : false; /** Filter out keys from an object. Returns `never` if `Exclude` is strictly equal to `Key`. Returns `never` if `Key` extends `Exclude`. Returns `Key` otherwise. @example ``` type Filtered = Filter<'foo', 'foo'>; //=> never ``` @example ``` type Filtered = Filter<'bar', string>; //=> never ``` @example ``` type Filtered = Filter<'bar', 'foo'>; //=> 'bar' ``` @see {Except} */ type Filter = IsEqual extends true ? never : (KeyType extends ExcludeType ? never : KeyType); /** Create a type from an object type without certain keys. 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. 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)). @example ``` import type {Except} from 'type-fest'; type Foo = { a: number; b: string; c: boolean; }; type FooWithoutA = Except; //=> {b: string}; ``` @category Object */ type Except = { [KeyType in keyof ObjectType as Filter]: ObjectType[KeyType]; }; /** @see Simplify */ interface SimplifyOptions { /** Do the simplification recursively. @default false */ deep?: boolean; } // Flatten a type without worrying about the result. type Flatten< AnyType, Options extends SimplifyOptions = {}, > = Options['deep'] extends true ? {[KeyType in keyof AnyType]: Simplify} : {[KeyType in keyof AnyType]: AnyType[KeyType]}; /** 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. @example ``` import type {Simplify} from 'type-fest'; type PositionProps = { top: number; left: number; }; type SizeProps = { width: number; height: number; }; // In your editor, hovering over `Props` will show a flattened object with all the properties. type Props = Simplify; ``` 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`. 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. 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 = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify` if you can't re-declare the `value`. @example ``` import type {Simplify} from 'type-fest'; interface SomeInterface { foo: number; bar?: string; baz: number | undefined; } type SomeType = { foo: number; bar?: string; baz: number | undefined; }; const literal = {foo: 123, bar: 'hello', baz: 456}; const someType: SomeType = literal; const someInterface: SomeInterface = literal; function fn(object: Record): void {} fn(literal); // Good: literal object type is sealed fn(someType); // Good: type is sealed fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened fn(someInterface as Simplify); // Good: transform an `interface` into a `type` ``` @link https://github.com/microsoft/TypeScript/issues/15300 @category Object */ type Simplify< AnyType, Options extends SimplifyOptions = {}, > = Flatten extends AnyType ? Flatten : AnyType; /** Create a type that makes the given keys optional. The remaining keys are kept as is. The sister of the `SetRequired` type. 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. @example ``` import type {SetOptional} from 'type-fest'; type Foo = { a: number; b?: string; c: boolean; } type SomeOptional = SetOptional; // type SomeOptional = { // a: number; // b?: string; // Was already optional and still is. // c?: boolean; // Is now optional. // } ``` @category Object */ type SetOptional = Simplify< // Pick just the keys that are readonly from the base type. Except & // Pick the keys that should be mutable from the base type and make them mutable. Partial> >; /** * Metadata to configure the stories for a component. * * @see [Default export](https://storybook.js.org/docs/api/csf#default-export) */ type Meta = [TCmpOrArgs] extends [ComponentType] ? ComponentAnnotations> : ComponentAnnotations; /** * Story function that represents a CSFv2 component example. * * @see [Named Story exports](https://storybook.js.org/docs/api/csf#named-story-exports) */ type StoryFn = [TCmpOrArgs] extends [ComponentType] ? AnnotatedStoryFn> : AnnotatedStoryFn; /** * Story object that represents a CSFv3 component example. * * @see [Named Story exports](https://storybook.js.org/docs/api/csf#named-story-exports) */ type StoryObj = [TMetaOrCmpOrArgs] extends [ { render?: ArgsStoryFn; component?: infer Component; args?: infer DefaultArgs; } ] ? Simplify<(Component extends ComponentType ? ComponentProps : unknown) & ArgsFromMeta> extends infer TArgs ? StoryAnnotations, SetOptional> : never : TMetaOrCmpOrArgs extends ComponentType ? StoryAnnotations> : StoryAnnotations; type AddMocks = Simplify<{ [T in keyof TArgs]: T extends keyof DefaultArgs ? DefaultArgs[T] extends (...args: any) => any & { mock: {}; } ? DefaultArgs[T] : TArgs[T] : TArgs[T]; }>; type Decorator = DecoratorFunction; type Loader = LoaderFunction; type StoryContext = StoryContext$1; type Preview = ProjectAnnotations; export { Decorator as D, Loader as L, Meta as M, Preview as P, StoryFn as S, StoryObj as a, StoryContext as b };