Socket
Socket
Sign inDemoInstall

@types/styled-components

Package Overview
Dependencies
6
Maintainers
1
Versions
81
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @types/styled-components

TypeScript definitions for styled-components


Version published
Weekly downloads
1.8M
decreased by-12.76%
Maintainers
1
Install size
1.64 MB
Created
Weekly downloads
 

Package description

What is @types/styled-components?

The @types/styled-components package provides TypeScript type definitions for the styled-components library, which is a popular CSS-in-JS library. These type definitions allow TypeScript developers to use styled-components in a type-safe manner, ensuring that styles are applied correctly and that component props are managed according to their expected types.

What are @types/styled-components's main functionalities?

Type-safe styled components

This feature allows developers to create styled components with TypeScript, providing type safety for props. The example shows a button component with a 'primary' prop that changes the background color based on its value.

import styled from 'styled-components';

interface ButtonProps {
  primary: boolean;
}

const Button = styled.button<ButtonProps>`
  background-color: ${props => props.primary ? 'blue' : 'gray'};
  color: white;
  padding: 10px 15px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
`;

Extending styles with TypeScript

This feature demonstrates how to extend an existing styled component while adding additional props with type definitions. The FancyButton extends BasicButton and includes a 'large' prop to adjust the font size.

import styled from 'styled-components';

const BasicButton = styled.button`
  color: white;
  background-color: black;
  padding: 5px 10px;
`;

interface FancyButtonProps {
  large: boolean;
}

const FancyButton = styled(BasicButton)<FancyButtonProps>`
  font-size: ${props => props.large ? '20px' : '12px'};
  border: 2px solid white;
`;

Other packages similar to @types/styled-components

Readme

Source

Installation

npm install --save @types/styled-components

Summary

This package contains type definitions for styled-components (https://github.com/styled-components/styled-components).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/styled-components.

Additional Details

Credits

These definitions were written by Igor Oleinikov, Ihor Chulinda, Jessica Franco, Jason Killian, Sebastian Silbermann, Matthew Wagerfield, Yuki Ito, Aaron Reisman, and Aaron Rose.

FAQs

Last updated on 06 Dec 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc