Ninguern
Ninguern
SSolidJS
Created by Ninguern on 12/7/2023 in #support
Error while installing dependencies on template
Got it, thank you
3 replies
SSolidJS
Created by Ninguern on 12/7/2022 in #support
How to properly type the `mergeProps` with Typescript?
Thanks @jesseb34r. I took a look at the answers and came to what I believe it's a good solution. I've updated my typescript to the ^4.9 version where I could use the satisfies operator and created a const for the default props. This seems to be the most organised solution I've found. Now it looks like this:
interface ButtonBaseProps extends JSX.ButtonHTMLAttributes<HTMLButtonElement> {
variant?: ButtonVariant;
color?: ColorNames;
}

const defaultProps = {
variant: "filled",
color: "primary",
type: "button",
} satisfies ButtonBaseProps;

function ButtonBase(props: ButtonBaseProps) {
const p = mergeProps(defaultProps, props);

return (
<button
class={join(
"flex items-center rounded-full py-2 outline-none",
getButtonStyles(p.variant, p.color),
p.children ? "px-4" : "px-2"
)}
{...p}
/>
);
}
interface ButtonBaseProps extends JSX.ButtonHTMLAttributes<HTMLButtonElement> {
variant?: ButtonVariant;
color?: ColorNames;
}

const defaultProps = {
variant: "filled",
color: "primary",
type: "button",
} satisfies ButtonBaseProps;

function ButtonBase(props: ButtonBaseProps) {
const p = mergeProps(defaultProps, props);

return (
<button
class={join(
"flex items-center rounded-full py-2 outline-none",
getButtonStyles(p.variant, p.color),
p.children ? "px-4" : "px-2"
)}
{...p}
/>
);
}
3 replies