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

Typescript error when extending from another base component #854

Closed
junagao opened this issue Oct 22, 2021 · 3 comments
Closed

Typescript error when extending from another base component #854

junagao opened this issue Oct 22, 2021 · 3 comments
Labels
P1 typescript TypeScript related

Comments

@junagao
Copy link

junagao commented Oct 22, 2021

Bug report

Describe the bug

I have a component that extends from a base component, example:

const BaseText = styled("div", {
  fontSize: "$1",
  variants: {
    variant: {
      blueberry: {
        color: "$purple"
      }
    }
  }
});

const Text = styled(BaseText, {
  variants: {
    variant: {
      tomato: {
        color: "$tomato"
      }
    }
  }
});
<Text variant="tomato">tomato</Text> // ok
<Text variant="blueberry">blueberry</Text> // typescript error

But when using the Text component with the variant in the BaseText, it returns the following Typescript error:
No overload matches this call.

Screenshot 2021-10-22 at 13 47 49

Shouldn't variants from the base component be inherited? It seems to be a Typescript error because it gets rendered correctly.

To Reproduce

  1. Go to https://codesandbox.io/s/crazy-mcnulty-kjjri
  2. Hover over variant in `blueberry
  3. See error

Expected behavior

Don't display any Typescript error.

System information

  • Version of Stitches: 1.2.5

Additional context

One workaround that made the error go away was adding an empty variant with the same name of the base component into the composed component:

const Text = styled(BaseText, {
  variants: {
    variant: {
      blueberry: {}, // <----- variant from base component but empty
      tomato: {
        color: "$tomato"
      }
    }
  }
});

Is there another solution without having to replicate all the base variants like so?

@peduarte
Copy link
Contributor

Hmm. This looks like a regression. Thanks for raising it!

@peduarte peduarte added P1 typescript TypeScript related labels Oct 25, 2021
@hadihallak
Copy link
Member

This is a duplicate of #749 which is now fixed under a canary release.
could you please upgrade to the latest canary1.2.7-0 and test again?

@junagao
Copy link
Author

junagao commented Mar 9, 2022

Hi @hadihallak, just tested it with the 1.2.7-0 and also 1.2.7 version but still not working. Check out the same codesandbox at: https://codesandbox.io/s/crazy-mcnulty-kjjri

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

No branches or pull requests

3 participants