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

Required attrs type fixes for 6.1.9 not applied when using union props #4303

Open
scott-m-sarsfield opened this issue May 3, 2024 · 1 comment

Comments

@scott-m-sarsfield
Copy link

scott-m-sarsfield commented May 3, 2024

Environment

System:

  • OS: macOS 14.4.1
  • CPU: (12) arm64 Apple M2 Pro
  • Memory: 200.98 MB / 16.00 GB
  • Shell: 5.9 - /bin/zsh

Binaries:

  • Node: 20.4.0 - ~/.nvm/versions/node/v20.4.0/bin/node
  • Yarn: 1.22.19 - ~/.nvm/versions/node/v20.4.0/bin/yarn
  • npm: 9.7.2 - ~/.nvm/versions/node/v20.4.0/bin/npm
  • Watchman: 2023.06.26.00 - /usr/local/bin/watchman

Reproduction

https://codesandbox.io/p/sandbox/quirky-bhaskara-24skvm

const One = (props: { x: "a" | "b" }) => null;

const Two = styled(One).attrs({ x: "a" })``;
const Three = styled(One).attrs({ x: "a" as const })``;

const App = () => {
  return (
    <>
      <Two /> // <-- error here
      <Three /> // (not here)
    </>
  );
};
No overload matches this call.
  Overload 1 of 2, '(props: PolymorphicComponentProps<"web", FastOmit<Substitute<{ x: "a" | "b"; }, Partial<RequiredFields<Attrs<FastOmit<{ x: "a" | "b"; }, never>>, "as">>>, never>, void, void, {}, {}>): Element', gave the following error.
    Property 'x' is missing in type '{}' but required in type 'FastOmit<Substitute<FastOmit<Substitute<{ x: "a" | "b"; }, Partial<RequiredFields<Attrs<FastOmit<{ x: "a" | "b"; }, never>>, "as">>>, never>, FastOmit<...>>, keyof ExecutionProps>'.
  Overload 2 of 2, '(props: FastOmit<Substitute<{ x: "a" | "b"; }, Partial<RequiredFields<Attrs<FastOmit<{ x: "a" | "b"; }, never>>, "as">>>, never>): ReactElement<...> | null', gave the following error.
    Property 'x' is missing in type '{}' but required in type 'FastOmit<Substitute<{ x: "a" | "b"; }, Partial<RequiredFields<Attrs<FastOmit<{ x: "a" | "b"; }, never>>, "as">>>, never>'.
    

Steps to reproduce

Create a component with a required union prop, wrap it with styled, and attempt to provide the value with attrs.

Expected Behavior

Required prop should no longer be required on the styled component. (And no additional typecasting should be required.)

Actual Behavior

Typescript error is thrown, saying that the prop is required and not passed in. Must pass as const to have it play nice again (which isn't particularly practical to go through a large codebase and address every instance that way).

@scott-m-sarsfield
Copy link
Author

...ah, great. Now it's more broken in 6.1.10 since they reverted the attrs changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant