The issue arises because both @emotion/core (used internally by Storybook) and styled-components define their own css prop, leading to a type conflict in TypeScript. When we import from Storybook, TypeScript tries to merge the types, causing the incompatibility.
Instead of using the css prop from styled-components directly, we can refactor our code to avoid the conflict altogether by using the styled API from styled-components. This approach is cleaner and sidesteps the need for additional type declarations.
Here’s a refactored version of our code that works seamlessly:
import React from "react";
import styled from "styled-components";
import { storiesOf } from "@storybook/react";
export default function App() {
const H1 = styled.h1`
background: red;
`;
return <H1>Hello world!</H1>;
}

If we still need to use the css prop for certain use cases, we can explore options like:
Work with our skilled React developers to accelerate your project and boost its performance.
Hire Reactjs Developers