@storybook/tanstack-react 0.0.0-pr-34863-sha-dc1c4dcb → 0.0.0-pr-34874-sha-dee98dbf

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
@@ -8,39 +8,31 @@ import { RoutesByPath, RouteOptions, ResolveParams, AnyContext } from '@tanstack
8
8
  import { BuilderOptions } from '@storybook/builder-vite';
9
9
  import { StorybookConfig as StorybookConfig$1 } from '@storybook/react-vite';
10
10
 
11
- /**
12
- Convert a union type to an intersection type.
13
-
14
- Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
15
-
16
- @example
17
- ```
18
- import type {UnionToIntersection} from 'type-fest';
11
+ declare global {
12
+ interface SymbolConstructor {
13
+ readonly observable: symbol;
14
+ }
15
+ }
19
16
 
20
- type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
17
+ /**
18
+ @see Simplify
19
+ */
20
+ interface SimplifyOptions {
21
+ /**
22
+ Do the simplification recursively.
21
23
 
22
- type Intersection = UnionToIntersection<Union>;
23
- //=> {the(): void} & {great(arg: string): void} & {escape: boolean}
24
- ```
24
+ @default false
25
+ */
26
+ deep?: boolean;
27
+ }
25
28
 
26
- @category Type
27
- */
28
- type UnionToIntersection<Union> = (
29
- // `extends unknown` is always going to be the case and is used to convert the
30
- // `Union` into a [distributive conditional
31
- // type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
32
- Union extends unknown
33
- // The union type is used as the only argument to a function since the union
34
- // of function arguments is an intersection.
35
- ? (distributedUnion: Union) => void
36
- // This won't happen.
37
- : never
38
- // Infer the `Intersection` type since TypeScript represents the positional
39
- // arguments of unions of functions as an intersection of the union.
40
- ) extends ((mergedIntersection: infer Intersection) => void)
41
- // The `& Union` is to ensure result of `UnionToIntersection<A | B>` is always assignable to `A | B`
42
- ? Intersection & Union
43
- : never;
29
+ // Flatten a type without worrying about the result.
30
+ type Flatten<
31
+ AnyType,
32
+ Options extends SimplifyOptions = {},
33
+ > = Options['deep'] extends true
34
+ ? {[KeyType in keyof AnyType]: Simplify<AnyType[KeyType], Options>}
35
+ : {[KeyType in keyof AnyType]: AnyType[KeyType]};
44
36
 
45
37
  /**
46
38
  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.
@@ -87,25 +79,27 @@ const literal = {foo: 123, bar: 'hello', baz: 456};
87
79
  const someType: SomeType = literal;
88
80
  const someInterface: SomeInterface = literal;
89
81
 
90
- declare function fn(object: Record<string, unknown>): void;
82
+ function fn(object: Record<string, unknown>): void {}
91
83
 
92
84
  fn(literal); // Good: literal object type is sealed
93
85
  fn(someType); // Good: type is sealed
94
- // @ts-expect-error
95
86
  fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
96
87
  fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
97
88
  ```
98
89
 
99
90
  @link https://github.com/microsoft/TypeScript/issues/15300
100
- @see {@link SimplifyDeep}
91
+
101
92
  @category Object
102
93
  */
103
- type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};
94
+ type Simplify<
95
+ AnyType,
96
+ Options extends SimplifyOptions = {},
97
+ > = Flatten<AnyType> extends AnyType
98
+ ? Flatten<AnyType, Options>
99
+ : AnyType;
104
100
 
105
101
  /**
106
- Omit any index signatures from the given object type, leaving only explicitly defined properties.
107
-
108
- This is the counterpart of `PickIndexSignature`.
102
+ Remove any index signatures from the given object type, so that only explicitly defined properties remain.
109
103
 
110
104
  Use-cases:
111
105
  - Remove overly permissive signatures from third-party types.
@@ -119,9 +113,8 @@ It relies on the fact that an empty object (`{}`) is assignable to an object wit
119
113
  ```
120
114
  const indexed: Record<string, unknown> = {}; // Allowed
121
115
 
122
- // @ts-expect-error
123
116
  const keyed: Record<'foo', unknown> = {}; // Error
124
- // TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
117
+ // => TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
125
118
  ```
126
119
 
127
120
  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:
@@ -130,75 +123,147 @@ Instead of causing a type error like the above, you can also use a [conditional
130
123
  type Indexed = {} extends Record<string, unknown>
131
124
  ? '✅ `{}` is assignable to `Record<string, unknown>`'
132
125
  : '❌ `{}` is NOT assignable to `Record<string, unknown>`';
133
-
134
- type IndexedResult = Indexed;
135
- //=> '✅ `{}` is assignable to `Record<string, unknown>`'
126
+ // => '✅ `{}` is assignable to `Record<string, unknown>`'
136
127
 
137
128
  type Keyed = {} extends Record<'foo' | 'bar', unknown>
138
- ? '✅ `{}` is assignable to `Record<\'foo\' | \'bar\', unknown>`'
139
- : '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`';
140
-
141
- type KeyedResult = Keyed;
142
- //=> '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`'
129
+ ? "✅ `{}` is assignable to `Record<'foo' | 'bar', unknown>`"
130
+ : "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`";
131
+ // => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
143
132
  ```
144
133
 
145
134
  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`...
146
135
 
147
136
  ```
148
- type OmitIndexSignature<ObjectType> = {
137
+ import type {RemoveIndexSignature} from 'type-fest';
138
+
139
+ type RemoveIndexSignature<ObjectType> = {
149
140
  [KeyType in keyof ObjectType // Map each key of `ObjectType`...
150
- ]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
141
+ ]: ObjectType[KeyType]; // ...to its original value, i.e. `RemoveIndexSignature<Foo> == Foo`.
151
142
  };
152
143
  ```
153
144
 
154
145
  ...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
155
146
 
156
147
  ```
157
- type OmitIndexSignature<ObjectType> = {
148
+ import type {RemoveIndexSignature} from 'type-fest';
149
+
150
+ type RemoveIndexSignature<ObjectType> = {
158
151
  [KeyType in keyof ObjectType
159
- // Is `{}` assignable to `Record<KeyType, unknown>`?
160
- as {} extends Record<KeyType, unknown>
161
- ? never // ✅ `{}` is assignable to `Record<KeyType, unknown>`
162
- : KeyType // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
152
+ // Is `{}` assignable to `Record<KeyType, unknown>`?
153
+ as {} extends Record<KeyType, unknown>
154
+ ? ... // ✅ `{}` is assignable to `Record<KeyType, unknown>`
155
+ : ... // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
163
156
  ]: ObjectType[KeyType];
164
157
  };
165
158
  ```
166
159
 
167
160
  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.
168
161
 
162
+ ```
163
+ import type {RemoveIndexSignature} from 'type-fest';
164
+
165
+ type RemoveIndexSignature<ObjectType> = {
166
+ [KeyType in keyof ObjectType
167
+ as {} extends Record<KeyType, unknown>
168
+ ? never // => Remove this `KeyType`.
169
+ : KeyType // => Keep this `KeyType` as it is.
170
+ ]: ObjectType[KeyType];
171
+ };
172
+ ```
173
+
169
174
  @example
170
175
  ```
171
- import type {OmitIndexSignature} from 'type-fest';
176
+ import type {RemoveIndexSignature} from 'type-fest';
172
177
 
173
- type Example = {
178
+ interface Example {
174
179
  // These index signatures will be removed.
175
- [x: string]: any;
176
- [x: number]: any;
177
- [x: symbol]: any;
178
- [x: `head-${string}`]: string;
179
- [x: `${string}-tail`]: string;
180
- [x: `head-${string}-tail`]: string;
181
- [x: `${bigint}`]: string;
182
- [x: `embedded-${number}`]: string;
180
+ [x: string]: any
181
+ [x: number]: any
182
+ [x: symbol]: any
183
+ [x: `head-${string}`]: string
184
+ [x: `${string}-tail`]: string
185
+ [x: `head-${string}-tail`]: string
186
+ [x: `${bigint}`]: string
187
+ [x: `embedded-${number}`]: string
183
188
 
184
189
  // These explicitly defined keys will remain.
185
190
  foo: 'bar';
186
191
  qux?: 'baz';
187
- };
192
+ }
188
193
 
189
- type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
190
- //=> {foo: 'bar'; qux?: 'baz'}
194
+ type ExampleWithoutIndexSignatures = RemoveIndexSignature<Example>;
195
+ // => { foo: 'bar'; qux?: 'baz' | undefined; }
191
196
  ```
192
197
 
193
- @see {@link PickIndexSignature}
194
198
  @category Object
195
199
  */
196
- type OmitIndexSignature<ObjectType> = {
200
+ type RemoveIndexSignature<ObjectType> = {
197
201
  [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
198
202
  ? never
199
203
  : KeyType]: ObjectType[KeyType];
200
204
  };
201
205
 
206
+ /**
207
+ Convert a union type to an intersection type using [distributive conditional types](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
208
+
209
+ Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
210
+
211
+ @example
212
+ ```
213
+ import type {UnionToIntersection} from 'type-fest';
214
+
215
+ type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
216
+
217
+ type Intersection = UnionToIntersection<Union>;
218
+ //=> {the(): void; great(arg: string): void; escape: boolean};
219
+ ```
220
+
221
+ A more applicable example which could make its way into your library code follows.
222
+
223
+ @example
224
+ ```
225
+ import type {UnionToIntersection} from 'type-fest';
226
+
227
+ class CommandOne {
228
+ commands: {
229
+ a1: () => undefined,
230
+ b1: () => undefined,
231
+ }
232
+ }
233
+
234
+ class CommandTwo {
235
+ commands: {
236
+ a2: (argA: string) => undefined,
237
+ b2: (argB: string) => undefined,
238
+ }
239
+ }
240
+
241
+ const union = [new CommandOne(), new CommandTwo()].map(instance => instance.commands);
242
+ type Union = typeof union;
243
+ //=> {a1(): void; b1(): void} | {a2(argA: string): void; b2(argB: string): void}
244
+
245
+ type Intersection = UnionToIntersection<Union>;
246
+ //=> {a1(): void; b1(): void; a2(argA: string): void; b2(argB: string): void}
247
+ ```
248
+
249
+ @category Type
250
+ */
251
+ type UnionToIntersection<Union> = (
252
+ // `extends unknown` is always going to be the case and is used to convert the
253
+ // `Union` into a [distributive conditional
254
+ // type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
255
+ Union extends unknown
256
+ // The union type is used as the only argument to a function since the union
257
+ // of function arguments is an intersection.
258
+ ? (distributedUnion: Union) => void
259
+ // This won't happen.
260
+ : never
261
+ // Infer the `Intersection` type since TypeScript represents the positional
262
+ // arguments of unions of functions as an intersection of the union.
263
+ ) extends ((mergedIntersection: infer Intersection) => void)
264
+ ? Intersection
265
+ : never;
266
+
202
267
  /** Union of every registered full path (e.g. `'/' | '/admin/users' | '/$libraryId/$version'`). */
203
268
  type RegisteredFullPath = keyof Register['router']['routesByPath'];
204
269
  type IsAppRouteTree<TRoute> = TRoute extends Register['router']['routeTree'] ? true : false;
@@ -324,7 +389,7 @@ interface TanStackTypes<TRoute = undefined, Path extends DefaultStoryPath<TRoute
324
389
  /** Extracts and unions all args types from an array of decorators. */
325
390
  type DecoratorsArgs<TRenderer extends Renderer, Decorators> = UnionToIntersection<Decorators extends DecoratorFunction<TRenderer, infer TArgs> ? TArgs : unknown>;
326
391
  type InferCombinedTypes<T, TArgs, Decorators> = ReactTypes & T & {
327
- args: Simplify<TArgs & Simplify<OmitIndexSignature<DecoratorsArgs<ReactTypes & T, Decorators>>>>;
392
+ args: Simplify<TArgs & Simplify<RemoveIndexSignature<DecoratorsArgs<ReactTypes & T, Decorators>>>>;
328
393
  };
329
394
  type Preview<TRoute extends AnyRoute | undefined = undefined> = ProjectAnnotations<ReactTypes & TanStackTypes<TRoute>>;
330
395
  declare function definePreview<TRoute extends AnyRoute | undefined = undefined, const TPath extends DefaultStoryPath<TRoute> = DefaultStoryPath<TRoute>, Addons extends PreviewAddon<never>[] = []>(preview: {
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_3y2aivro9bk from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_3y2aivro9bk from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_3y2aivro9bk from "node:module";
1
+ import CJS_COMPAT_NODE_URL_1827c7h9ksp from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_1827c7h9ksp from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_1827c7h9ksp from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_3y2aivro9bk.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_3y2aivro9bk.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_3y2aivro9bk.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_1827c7h9ksp.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_1827c7h9ksp.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_1827c7h9ksp.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
package/dist/preset.js CHANGED
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_3y2aivro9bk from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_3y2aivro9bk from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_3y2aivro9bk from "node:module";
1
+ import CJS_COMPAT_NODE_URL_1827c7h9ksp from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_1827c7h9ksp from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_1827c7h9ksp from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_3y2aivro9bk.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_3y2aivro9bk.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_3y2aivro9bk.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_1827c7h9ksp.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_1827c7h9ksp.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_1827c7h9ksp.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/tanstack-react",
3
- "version": "0.0.0-pr-34863-sha-dc1c4dcb",
3
+ "version": "0.0.0-pr-34874-sha-dee98dbf",
4
4
  "description": "Storybook for TanStack (React, Vite): Router and Start ready Storybook framework",
5
5
  "keywords": [
6
6
  "storybook",
@@ -75,9 +75,9 @@
75
75
  "!src/**/*"
76
76
  ],
77
77
  "dependencies": {
78
- "@storybook/builder-vite": "0.0.0-pr-34863-sha-dc1c4dcb",
79
- "@storybook/react": "0.0.0-pr-34863-sha-dc1c4dcb",
80
- "@storybook/react-vite": "0.0.0-pr-34863-sha-dc1c4dcb"
78
+ "@storybook/builder-vite": "0.0.0-pr-34874-sha-dee98dbf",
79
+ "@storybook/react": "0.0.0-pr-34874-sha-dee98dbf",
80
+ "@storybook/react-vite": "0.0.0-pr-34874-sha-dee98dbf"
81
81
  },
82
82
  "devDependencies": {
83
83
  "@tanstack/react-router": "^1.168.10",
@@ -95,7 +95,7 @@
95
95
  "@tanstack/start-client-core": "^1.167.9",
96
96
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
97
97
  "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
98
- "storybook": "^0.0.0-pr-34863-sha-dc1c4dcb",
98
+ "storybook": "^0.0.0-pr-34874-sha-dee98dbf",
99
99
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
100
100
  },
101
101
  "peerDependenciesMeta": {