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! :)

Latest comments (0)