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

TS doesn't see props after «styled()» of «withTheme(styled.button... #130

Open
Opty1712 opened this issue Dec 25, 2021 · 2 comments
Open

Comments

@Opty1712
Copy link

Opty1712 commented Dec 25, 2021

Linking with callstack/linaria#893

Environment

  • macOS Monterrey
  • yarn 3 (PnP)
  • TS 4.5.2
  • "@linaria/core": "^3.0.0-beta.15",
  • "@linaria/react": "^3.0.0-beta.15",
  • "@linaria/babel-preset": "^3.0.0-beta.15",
  • "@linaria/shaker": "^3.0.0-beta.15",
  • "@linaria/webpack-loader": "^3.0.0-beta.16",
  • "@callstack/react-theme-provider": "^3.0.7",
  • bundler - storybook@6
  • node 14.17.6

Description

export const Select = () => (
	<OptionButton type="button" data-qa-id="listItem-btn" />
);

const Button = withTheme(styled.button<Theme>`
	width: 100%;
`);

export const OptionButton = styled(Button)`
	width: 50%;
`;

image

image

If I add Button directly - no error
image

If I remove withTheme - no error too
image

Reproducible Demo

https://codesandbox.io/s/wild-grass-g4e0u?file=/src/App.tsx

@Opty1712 Opty1712 changed the title TS don't see props after «styled()» of «withTheme(styled.button... TS doesn't see props after «styled()» of «withTheme(styled.button... Dec 25, 2021
@R4YM3
Copy link

R4YM3 commented Feb 7, 2022

@Opty1712 did you found a work around for this?

@R4YM3
Copy link

R4YM3 commented Feb 9, 2022

Yesterday i took some time to debug this and found what is going on.

You have:

export const Select = () => (
	<OptionButton type="button" data-qa-id="listItem-btn" />
);

const Button = withTheme(styled.button<Theme>`
	width: 100%;
`);

export const OptionButton = styled(Button)`
	width: 50%;
`;

It looks that your Theme type is (when looking at the error)

interface Theme {
	type: string;
	"data-ga-id": string;
}

You need to make another type:

interface IWithTheme {
	theme: Theme;
}

and pass this on:

const Button = withTheme(styled.button<IWithTheme>`
	width: 100%;
`);

It wasn't obvious for me aswell, but withTheme HOC the theme is set in the theme prop.
Which is ofcourse logical, since you could also pass other props.

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

2 participants