Skip to content

Commit

Permalink
fix(writer)!: use type alias instead of interface for RestProps (#138)
Browse files Browse the repository at this point in the history
Fixes #137
  • Loading branch information
metonym authored Oct 27, 2024
1 parent 7b9e6c8 commit d9cf04a
Show file tree
Hide file tree
Showing 220 changed files with 1,100 additions and 507 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import type { SvelteHTMLElements } from "svelte/elements";

type RestProps = SvelteHTMLElements["button"];

export interface ButtonProps extends RestProps {
type $Props = {
/**
* @default "button"
*/
Expand All @@ -53,7 +53,11 @@ export interface ButtonProps extends RestProps {
* @default false
*/
primary?: boolean;
}

[key: `data-${string}`]: any;
};

export type ButtonProps = Omit<RestProps, keyof $Props> & $Props;

export default class Button extends SvelteComponentTyped<
ButtonProps,
Expand Down Expand Up @@ -83,7 +87,7 @@ import type { SvelteHTMLElements } from "svelte/elements";

type RestProps = SvelteHTMLElements["button"];

export interface ButtonProps extends RestProps {
type $Props = {
/**
* @default "button"
*/
Expand All @@ -94,7 +98,9 @@ export interface ButtonProps extends RestProps {
* @default false
*/
primary?: boolean;
}
};

export type ButtonProps = Omit<RestProps, keyof $Props> & $Props;

export default class Button extends SvelteComponentTyped<
ButtonProps,
Expand Down
12 changes: 5 additions & 7 deletions src/writer/writer-ts-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,17 @@ function genPropDef(def: Pick<ComponentDocApi, "props" | "rest_props" | "moduleN

prop_def = `
${extend_tag_map ? `type RestProps = ${extend_tag_map};\n` : ""}
export interface ${props_name}${genericsName} extends ${
def.extends !== undefined ? `${def.extends.interface}, ` : ""
}RestProps {
type $Props${genericsName} = {
${props}
${dataAttributes}
}
};
export type ${props_name}${genericsName} = Omit<RestProps, keyof $Props${genericsName}> & $Props${genericsName};
`;
} else {
prop_def = `
export interface ${props_name}${genericsName} ${
def.extends !== undefined ? `extends ${def.extends.interface}` : ""
} {
export type ${props_name}${genericsName} = ${def.extends !== undefined ? `${def.extends.interface} & ` : ""} {
${props}
}
`;
Expand Down
Loading

0 comments on commit d9cf04a

Please sign in to comment.