sveld 0.30.2 → 0.31.0
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/README.md +49 -18
- package/lib/index.js +98 -98
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -139,6 +139,7 @@ export default class Button extends SvelteComponentTyped<
|
|
|
139
139
|
- [Context API](#context-api)
|
|
140
140
|
- [@restProps](#restprops)
|
|
141
141
|
- [@extendProps](#extendprops)
|
|
142
|
+
- [@template](#template)
|
|
142
143
|
- [@generics](#generics)
|
|
143
144
|
- [@component comments](#component-comments)
|
|
144
145
|
- [Accessor Props](#accessor-props)
|
|
@@ -1544,24 +1545,22 @@ export const secondary = true;
|
|
|
1544
1545
|
import Button from "./Button.svelte";
|
|
1545
1546
|
```
|
|
1546
1547
|
|
|
1547
|
-
### `@
|
|
1548
|
-
|
|
1549
|
-
Currently, to define generics for a Svelte component, you must use [`generics` attribute](https://github.com/dummdidumm/rfcs/blob/bfb14dc56a70ec6ddafebf2242b8e1500e06a032/text/ts-typing-props-slots-events.md#generics) on the script tag. Note that this feature is [experimental](https://svelte.dev/docs/typescript#experimental-advanced-typings) and may change in the future.
|
|
1548
|
+
### `@template`
|
|
1550
1549
|
|
|
1551
|
-
|
|
1550
|
+
Svelte supports defining generics via the [`generics` attribute](https://svelte.dev/docs/svelte/typescript) on the script tag, but this requires `lang="ts"`.
|
|
1552
1551
|
|
|
1553
1552
|
```svelte
|
|
1554
|
-
<!--
|
|
1555
|
-
<script generics="Row extends DataTableRow = any"></script>
|
|
1553
|
+
<!-- Requires lang="ts" -->
|
|
1554
|
+
<script lang="ts" generics="Row extends DataTableRow = any"></script>
|
|
1556
1555
|
```
|
|
1557
1556
|
|
|
1558
|
-
Because `sveld` is designed to support JavaScript-only usage as a baseline, the API design to specify generics uses
|
|
1557
|
+
Because `sveld` is designed to support JavaScript-only usage as a baseline, the API design to specify generics uses the standard JSDoc `@template` tag. The `@generics` tag is also supported as an alias.
|
|
1559
1558
|
|
|
1560
|
-
**Signature:**
|
|
1559
|
+
**Signature:** Uses standard [JSDoc `@template` syntax](https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#template):
|
|
1561
1560
|
|
|
1562
1561
|
```js
|
|
1563
1562
|
/**
|
|
1564
|
-
* @
|
|
1563
|
+
* @template {Constraint} [Name=Default]
|
|
1565
1564
|
*/
|
|
1566
1565
|
```
|
|
1567
1566
|
|
|
@@ -1569,7 +1568,7 @@ Because `sveld` is designed to support JavaScript-only usage as a baseline, the
|
|
|
1569
1568
|
|
|
1570
1569
|
```js
|
|
1571
1570
|
/**
|
|
1572
|
-
* @
|
|
1571
|
+
* @template {DataTableRow} [Row=DataTableRow]
|
|
1573
1572
|
*/
|
|
1574
1573
|
```
|
|
1575
1574
|
|
|
@@ -1624,13 +1623,12 @@ Because `sveld` is designed to support JavaScript-only usage as a baseline, the
|
|
|
1624
1623
|
The generated TypeScript definition will resemble the following:
|
|
1625
1624
|
|
|
1626
1625
|
```ts
|
|
1627
|
-
|
|
1628
|
-
export type ComponentProps<Row extends DataTableRow = any> = {
|
|
1626
|
+
export type ComponentProps<Row extends DataTableRow = DataTableRow> = {
|
|
1629
1627
|
rows?: ReadonlyArray<Row>;
|
|
1630
1628
|
};
|
|
1631
1629
|
|
|
1632
1630
|
export default class Component<
|
|
1633
|
-
Row extends DataTableRow =
|
|
1631
|
+
Row extends DataTableRow = DataTableRow,
|
|
1634
1632
|
> extends SvelteComponentTyped<
|
|
1635
1633
|
ComponentProps<Row>,
|
|
1636
1634
|
Record<string, any>,
|
|
@@ -1638,24 +1636,57 @@ export default class Component<
|
|
|
1638
1636
|
> {}
|
|
1639
1637
|
```
|
|
1640
1638
|
|
|
1641
|
-
For
|
|
1639
|
+
For multiple generics, use separate `@template` tags:
|
|
1642
1640
|
|
|
1643
1641
|
```js
|
|
1644
1642
|
/**
|
|
1645
|
-
* @
|
|
1643
|
+
* @template {DataTableRow} [Row=DataTableRow]
|
|
1644
|
+
* @template {DataTableRow} [Header=DataTableRow]
|
|
1646
1645
|
*/
|
|
1647
1646
|
```
|
|
1648
1647
|
|
|
1649
1648
|
```ts
|
|
1650
|
-
export type ComponentProps<
|
|
1649
|
+
export type ComponentProps<
|
|
1650
|
+
Row extends DataTableRow = DataTableRow,
|
|
1651
|
+
Header extends DataTableRow = DataTableRow,
|
|
1652
|
+
> = { ... };
|
|
1651
1653
|
|
|
1652
|
-
export default class Component<
|
|
1653
|
-
|
|
1654
|
+
export default class Component<
|
|
1655
|
+
Row extends DataTableRow = DataTableRow,
|
|
1656
|
+
Header extends DataTableRow = DataTableRow,
|
|
1657
|
+
> extends SvelteComponentTyped<
|
|
1658
|
+
ComponentProps<Row, Header>,
|
|
1654
1659
|
Record<string, any>,
|
|
1655
1660
|
Record<string, any>
|
|
1656
1661
|
> {}
|
|
1657
1662
|
```
|
|
1658
1663
|
|
|
1664
|
+
### `@generics`
|
|
1665
|
+
|
|
1666
|
+
As an alternative to `@template`, sveld also supports a custom `@generics` tag. Unlike `@template`, which is [officially supported by JSDoc/TypeScript](https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#template), `@generics` is sveld-specific. However, its syntax can be more readable since the full constraint is written inline:
|
|
1667
|
+
|
|
1668
|
+
```js
|
|
1669
|
+
/**
|
|
1670
|
+
* @generics {Row extends DataTableRow = DataTableRow} Row
|
|
1671
|
+
*/
|
|
1672
|
+
```
|
|
1673
|
+
|
|
1674
|
+
This is equivalent to:
|
|
1675
|
+
|
|
1676
|
+
```js
|
|
1677
|
+
/**
|
|
1678
|
+
* @template {DataTableRow} [Row=DataTableRow]
|
|
1679
|
+
*/
|
|
1680
|
+
```
|
|
1681
|
+
|
|
1682
|
+
For multiple generics, use a single `@generics` tag with comma-separated names:
|
|
1683
|
+
|
|
1684
|
+
```js
|
|
1685
|
+
/**
|
|
1686
|
+
* @generics {Row extends DataTableRow = DataTableRow, Header extends DataTableRow = DataTableRow} Row,Header
|
|
1687
|
+
*/
|
|
1688
|
+
```
|
|
1689
|
+
|
|
1659
1690
|
### `@component` comments
|
|
1660
1691
|
|
|
1661
1692
|
The Svelte Language Server supports component-level comments through the following syntax: `<!-- @component [comment] -->`.
|