Skip to content
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

constraints lead to error on @types/react^17 #3

Closed
nasheomirro opened this issue Jan 22, 2023 · 1 comment
Closed

constraints lead to error on @types/react^17 #3

nasheomirro opened this issue Jan 22, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@nasheomirro
Copy link
Owner

Adding constraints lead to errors when using newer versions of @types/react.

const Button: PolymorphicComponent<"button", {},  "button" | "a"> = ({
  as: As = "button",
  ...props
}) => {
  // error when props are spread
  return <As {...props} />;
};

This is also the case when using a single prop:

const Button: PolymorphicComponent<"button", {}, "button" | "a"> = ({
  as: As = "button",
  onClick,
}) => {
  // error: 'As' doesn't match
  return <As onClick={onClick} />;
};

I think this has something to do with the props being known, props become ComponentProps<"button"> | ComponentProps<"a"> instead of the usual ComponentProps<ElementType<any>>. As can either be "button" | "a" so there is a mismatch where As could be "button" but it's props could be ComponentProps<"a">

@nasheomirro nasheomirro added the bug Something isn't working label Jan 22, 2023
@nasheomirro nasheomirro self-assigned this Jan 22, 2023
@BrandanKing
Copy link

Hi, I am trying to use onlyAs to create a button that can have the following types OnlyAs<'button' | 'a' | typeof Link> where Link is next/link. However, whenever I add this I get the error 'href' is declared here. It appears that it doesn't apply unknown to typeof props

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants