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

error TS4023 when compiling a library that uses "styled-components": "^6.1.9" #4299

Open
akkadaya opened this issue May 2, 2024 · 4 comments

Comments

@akkadaya
Copy link
Contributor

akkadaya commented May 2, 2024

error TS4023: Exported variable 'StyledComponent1' has or is using name 'IStyledComponentBase' from external module ".../node_modules/styled-components/dist/types" but cannot be named.

I could compile the library after exporting the IStyledComponentBase interface in node_modules/styled-components/dist/types.d.ts

Here is the link to the interface in this repo:

interface IStyledComponentBase<R extends Runtime, Props extends object = BaseObject>

Am I doing something wrong? or is it a bug in styled-components that needs to be fixed?

@TomasMoratoPerezPorro
Copy link

I'm having an issue that coul be related, after upgrading to Styled 6 i get the following error in all my styled components:

export const Relative = styled(Div)<PositionProps>`
	position: relative;
	z-index: ${({ zIndex }) => zIndex};
`;

Exported variable 'Relative' has or is using name 'IStyledComponentBase' from external module "C:/.../project/node_modules/styled-components/dist/types" but cannot be named.ts(4023)

Any idea of how could it be fixed ?

@akkadaya
Copy link
Contributor Author

akkadaya commented May 3, 2024

I raised a PR to fix it #4300

Meanwhile, use this script as a workaround.

#!/usr/bin/env bash

set -euo pipefail

echo 'Applying fix to Styled-Components types...'

os=$(uname -s)

case $os in
Darwin)
    sed -i '' 's/^interface IStyledComponentBase/export interface IStyledComponentBase/g' node_modules/styled-components/dist/types.d.ts
    ;;
Linux)
    sed -i 's/^interface IStyledComponentBase/export interface IStyledComponentBase/g' node_modules/styled-components/dist/types.d.ts
    ;;
esac

Let's say you save it in scripts/post_install.sh and then add this line to your package.json scripts

  "scripts": {
    ...
    "postinstall": "scripts/post_install.sh"

make sure to make the script executable by running

chmod +x post_install.sh

@quantizor
Copy link
Contributor

Fix should be here I think, though I don't understand why TS should require an internal type to be exposed https://github.com/styled-components/styled-components/releases/tag/v6.1.10

@akkadaya
Copy link
Contributor Author

akkadaya commented May 7, 2024

Thank you @quantizor

When you hover over a component created by Styled Components, it infers the type IStyledComponentBase
image

But I believe it was meant to be IStyledComponent instead
image

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

3 participants