DEV Community 👩‍💻👨‍💻

Cover image for Type Checking Styled Components
Caleb Lewis
Caleb Lewis

Posted on

Type Checking Styled Components

I've just started using styled components and it took way too long to figure out how to get type checking for styled components with props:

styled component with error

If you're using typescript, your editor will give you this warning:

the error

Luckily, styled components can have generics types, so we just need to create a type for the its props and pass it as a generic:

styled component without error

No more type errors! :)

Top comments (0)

Now it's your turn.

🗒 Share a tutorial
🤔 Reflect on your coding journey
❓ Ask a question
Create an account to join hundreds of thousands of DEV members on their journey.