diff --git a/tests/__snapshots__/fixtures.test.ts.snap b/tests/__snapshots__/fixtures.test.ts.snap index eabb303..91900df 100644 --- a/tests/__snapshots__/fixtures.test.ts.snap +++ b/tests/__snapshots__/fixtures.test.ts.snap @@ -1141,9 +1141,31 @@ exports[`fixtures (JSON) "typed-props/input.svelte" 1`] = ` }" `; +exports[`fixtures (JSON) "generics/Test.svelte" 1`] = ` +"{ + "props": [], + "moduleExports": [], + "slots": [], + "events": [], + "typedefs": [], + "generics": null +}" +`; + exports[`fixtures (JSON) "generics/input.svelte" 1`] = ` "{ "props": [ + { + "name": "headers", + "kind": "let", + "type": "ReadonlyArray>", + "value": "[]", + "isFunction": false, + "isFunctionDeclaration": false, + "isRequired": false, + "constant": false, + "reactive": false + }, { "name": "rows", "kind": "let", @@ -1167,9 +1189,19 @@ exports[`fixtures (JSON) "generics/input.svelte" 1`] = ` "events": [], "typedefs": [ { - "type": "Record", + "type": "{ id: string | number; [key: string]: any; }", "name": "DataTableRow", - "ts": "type DataTableRow = Record" + "ts": "interface DataTableRow { id: string | number; [key: string]: any; }" + }, + { + "type": "Exclude", + "name": "DataTableKey", + "ts": "type DataTableKey = Exclude" + }, + { + "type": "{ key: DataTableKey; value: string; }", + "name": "DataTableHeader", + "ts": "interface DataTableHeader { key: DataTableKey; value: string; }" } ], "generics": [ @@ -1796,12 +1828,36 @@ export default class TypedProps extends SvelteComponentTyped, {}> {} +" +`; + exports[`fixtures (TypeScript) "generics/input.svelte" 1`] = ` "import type { SvelteComponentTyped } from "svelte"; -export type DataTableRow = Record; +export interface DataTableRow { + id: string | number; + [key: string]: any; +} + +export type DataTableKey = Exclude; + +export interface DataTableHeader { + key: DataTableKey; + value: string; +} export interface GenericsProps { + /** + * @default [] + */ + headers?: ReadonlyArray>; + /** * @default [] */ @@ -1815,3 +1871,69 @@ export default class Generics extends S > {} " `; + +exports[`fixtures (TypeScript) "svg-props/input.svelte" 1`] = ` +"import type { SvelteComponentTyped } from "svelte"; +import type { SvelteHTMLElements } from "svelte/elements"; + +type RestProps = SvelteHTMLElements["svg"]; + +export interface SvgPropsProps extends RestProps { + [key: \`data-${string}\`]: any; +} + +export default class SvgProps extends SvelteComponentTyped, {}> {} +" +`; + +exports[`fixtures (TypeScript) "rest-props/input.svelte" 1`] = ` +"import type { SvelteComponentTyped } from "svelte"; +import type { SvelteHTMLElements } from "svelte/elements"; + +type RestProps = SvelteHTMLElements["h1"]; + +export interface RestPropsProps extends RestProps { + [key: \`data-${string}\`]: any; +} + +export default class RestProps extends SvelteComponentTyped, {}> {} +" +`; + +exports[`fixtures (TypeScript) "rest-props-multiple/input.svelte" 1`] = ` +"import type { SvelteComponentTyped } from "svelte"; +import type { SvelteHTMLElements } from "svelte/elements"; + +type RestProps = SvelteHTMLElements["h1"] & SvelteHTMLElements["span"]; + +export interface RestPropsMultipleProps extends RestProps { + /** + * @default false + */ + edit?: boolean; + + /** + * @default false + */ + heading?: boolean; + + [key: \`data-${string}\`]: any; +} + +export default class RestPropsMultiple extends SvelteComponentTyped, {}> {} +" +`; + +exports[`fixtures (TypeScript) "anchor-props/input.svelte" 1`] = ` +"import type { SvelteComponentTyped } from "svelte"; +import type { SvelteHTMLElements } from "svelte/elements"; + +type RestProps = SvelteHTMLElements["a"]; + +export interface AnchorPropsProps extends RestProps { + [key: \`data-${string}\`]: any; +} + +export default class AnchorProps extends SvelteComponentTyped, { default: {} }> {} +" +`; diff --git a/tests/fixtures/generics/Test.svelte b/tests/fixtures/generics/Test.svelte new file mode 100644 index 0000000..d5d69ba --- /dev/null +++ b/tests/fixtures/generics/Test.svelte @@ -0,0 +1,26 @@ + + + + {#each rows as row} + {row.name} + {/each} + diff --git a/tests/fixtures/generics/input.svelte b/tests/fixtures/generics/input.svelte new file mode 100644 index 0000000..30962c8 --- /dev/null +++ b/tests/fixtures/generics/input.svelte @@ -0,0 +1,17 @@ + + + diff --git a/tests/fixtures/generics/output.d.ts b/tests/fixtures/generics/output.d.ts new file mode 100644 index 0000000..5cbba14 --- /dev/null +++ b/tests/fixtures/generics/output.d.ts @@ -0,0 +1,31 @@ +import type { SvelteComponentTyped } from "svelte"; + +export interface DataTableRow { + id: string | number; + [key: string]: any; +} + +export type DataTableKey = Exclude; + +export interface DataTableHeader { + key: DataTableKey; + value: string; +} + +export interface GenericsProps { + /** + * @default [] + */ + headers?: ReadonlyArray>; + + /** + * @default [] + */ + rows?: ReadonlyArray; +} + +export default class Generics extends SvelteComponentTyped< + GenericsProps, + Record, + { default: { rows: ReadonlyArray } } +> {} diff --git a/tests/fixtures/generics/output.json b/tests/fixtures/generics/output.json new file mode 100644 index 0000000..ae418bc --- /dev/null +++ b/tests/fixtures/generics/output.json @@ -0,0 +1,56 @@ +{ + "props": [ + { + "name": "headers", + "kind": "let", + "type": "ReadonlyArray>", + "value": "[]", + "isFunction": false, + "isFunctionDeclaration": false, + "isRequired": false, + "constant": false, + "reactive": false + }, + { + "name": "rows", + "kind": "let", + "type": "ReadonlyArray", + "value": "[]", + "isFunction": false, + "isFunctionDeclaration": false, + "isRequired": false, + "constant": false, + "reactive": false + } + ], + "moduleExports": [], + "slots": [ + { + "name": "__default__", + "default": true, + "slot_props": "{ rows: ReadonlyArray }" + } + ], + "events": [], + "typedefs": [ + { + "type": "{ id: string | number; [key: string]: any; }", + "name": "DataTableRow", + "ts": "interface DataTableRow { id: string | number; [key: string]: any; }" + }, + { + "type": "Exclude", + "name": "DataTableKey", + "ts": "type DataTableKey = Exclude" + }, + { + "type": "{ key: DataTableKey; value: string; }", + "name": "DataTableHeader", + "ts": "interface DataTableHeader { key: DataTableKey; value: string; }" + } + ], + "generics": [ + "Row", + "Row extends DataTableRow = DataTableRow" + ] +} \ No newline at end of file