sveld 0.32.2 → 0.32.3

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.
Files changed (3) hide show
  1. package/README.md +35 -0
  2. package/lib/index.js +587 -585
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1484,6 +1484,41 @@ export default class Component extends SvelteComponentTyped<
1484
1484
  > {}
1485
1485
  ```
1486
1486
 
1487
+ #### Discriminated unions in event details
1488
+
1489
+ When the event detail is a union (or any non-object shape), use `@type` to declare it directly. An explicit `@type` takes precedence over `@property` tags, so the union is preserved verbatim in the emitted `.d.ts` rather than being flattened into independent property unions. The special form `@type {object}` is the only exception — it signals that the shape should be built from the `@property` tags (as shown above).
1490
+
1491
+ **Example:**
1492
+
1493
+ ```svelte
1494
+ <script>
1495
+ /**
1496
+ * @event sort
1497
+ * @type {{ key: null; direction: "none" } | { key: string; direction: "ascending" | "descending" }}
1498
+ * Dispatched when a sortable column header would change the active sort.
1499
+ */
1500
+
1501
+ import { createEventDispatcher } from "svelte";
1502
+
1503
+ const dispatch = createEventDispatcher();
1504
+ </script>
1505
+ ```
1506
+
1507
+ Output:
1508
+
1509
+ ```ts
1510
+ export default class Component extends SvelteComponentTyped<
1511
+ ComponentProps,
1512
+ {
1513
+ /** Dispatched when a sortable column header would change the active sort. */
1514
+ sort: CustomEvent<{ key: null; direction: "none" } | { key: string; direction: "ascending" | "descending" }>;
1515
+ },
1516
+ Record<string, never>
1517
+ > {}
1518
+ ```
1519
+
1520
+ Any free-text prose after the tags is attached to the event description, not to a property doc.
1521
+
1487
1522
  ### Context API
1488
1523
 
1489
1524
  `sveld` automatically generates TypeScript definitions for Svelte's `setContext`/`getContext` API by extracting types from JSDoc annotations on the context values.