-
-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing type in PolymorphicProps type #78
Comments
Hi, thanks for reporting the issue. Since the code is short I can add it myself. However, i've noticed that your fix don't work in this case: const Button = (props: ButtonProps) => {
return <KobalteButton {...props} />;
};
// A button with additional custom props
const IconButton = (props: ButtonProps & { icon: JSX.Element }) => {
return <KobalteButton {...props} />;
};
const App = () => {
return (
<Button
as={IconButton}
icon="icon" {/* error here: prop not recognized */}
>
Button
</Button>
);
}; The only solution that i've found is to wrap If you have any idea feel free to make a PR and thanks for your time. |
The only thing I can come up with is to wrap Should be: export type Simplify<T> = T extends any ? { [KeyType in keyof T]: T[KeyType] } : T; Then the type output should be flattened out, which I prefer tbh, even over the simplest type name showing up as hint. |
I was able to use like so: import type { PolymorphicProps, As } from "@kobalte/utils";
import type { JSX } from "solid-js";
import { Button as KButton } from "@kobalte/core";
import { splitProps } from "solid-js";
type ButtonOwnProps = KButton.ButtonRootOptions & {
children?: JSX.Element
class?: string // your custom props
}
export type ButtonProps<T extends As = "button"> = PolymorphicProps<T, ButtonOwnProps>;
export function Button<T extends As = "button">(props: ButtonProps<T>): JSX.Element {
const [local, rest] = splitProps(props, ["class", "children"]);
return (
<KButton.Root class={local.class} {...rest}>
{local.children}
</KButton.Root>
);
} And the usage: function App() {
return (
<Button as="a" href="http://it.works.com">Click me!</Button>
)
} |
Oh yeah, its a nice workaround. |
Describe the bug
Current PolymorphicProps type is missing a type in the
as
prop causing an error when extending the component,should be:
To Reproduce
https://codesandbox.io/s/typescript-playground-export-forked-50p1o0?file=/index.tsx
In this codesandbox I provided a fix which is in the
fixedImpl.ts
file, you can easily toggle between the imported files to see each implementation.Expected behavior
Should accept any ValidComponent passed to
as
propScreenshots
Additional context
This is actually the first issue I've opened, so, please, let me know if I can improve anything.
I know its a small fix but I would be super down to do a PR for this, but that would be a first for me also and I think I'd need some guidance on that.
The text was updated successfully, but these errors were encountered: