It's described in the official documentation.

In a .d.ts file add this:

import 'styled-components';

declare module 'styled-components' {
  export interface DefaultTheme {
     borderRadius: string;
     color: string;
  }
}

Answer from Sérgio Junior on Stack Overflow
🌐
styled-components
styled-components.com › docs › advanced
styled-components
styled-components now natively ... <style> tags that React 19 hoists and deduplicates. ... Since ThemeProvider is a no-op in RSC, use CSS custom properties for theming instead....
🌐
GitHub
github.com › styled-components › styled-components › issues › 1847
Typescript error in docs example for ThemeProvider · Issue #1847 · styled-components/styled-components
July 13, 2018 - Exported variable ThemeProvider has or is using name React.ComponentClass from external module ./node_modules/@types/react/index but cannot be named. ... const { default: styled, css, injectGlobal, keyframes, ThemeProvider } = styledComponents as ThemedStyledComponentsModule<ThemeInterface>;
Author   teddybradford
🌐
GitHub
github.com › styled-components › styled-components › issues › 2960
Default theme for components without parent ThemeProvider · Issue #2960 · styled-components/styled-components
January 13, 2020 - https://github.com/styled-components/styled-components/blob/master/packages/styled-components/src/models/ThemeProvider.js#L15 · export const ThemeContext: Context<Theme | void> = React.createContext(); Note that the context is created without a default value (React.createContext(defaultValue)), which would be used by any context consumers when they don't have a parent. ... Create a library constructor module that re-exports the whole library scoped to a custom context: const {styled, ThemeProvider} = createStyledComponents(defaultTheme)
Author   alexkrolick
🌐
GitHub
github.com › jacob-ebey › styled-components-ts › issues › 18
No exported member 'StyledComponentClass' · Issue #18 · jacob-ebey/styled-components-ts
November 29, 2018 - I get this error when using this package: project/node_modules/styled-components-ts/lib/styled-components-ts.d.ts (3,32): Module '"project/node_modules/@types/styled-components/index"' has no expor...
Author   elie222
🌐
GitHub
github.com › styled-components › jest-styled-components › issues › 134
property not found using styled-system · Issue #134 · styled-components/jest-styled-components
April 11, 2018 - import styled, { ThemeProvider } from 'styled-components'; import { theme } from 'styled-system'; export const StyledMyComponent = styled.span` color: ${theme('colors.primary')}; `; const colors = { primary: '#000000', }; export const MyComponent = props => ( <ThemeProvider theme={{ colors }}> <StyledMyComponent>{props.children}</StyledMyComponent> </ThemeProvider> );
🌐
Theme-ui
theme-ui.com › migrating
Migrating – Theme UI
We no longer export internal React context named as Context 😅 It wasn't and it's still not public API, but if you used it and you really need it, you can grab it as __ThemeUIContext. (But please don't do this. Use ThemeProvider from @theme-ui/core for local theme overrides instead.) Styled will be removed in v0.7.
Find elsewhere
🌐
MUI
mui.com › material-ui › migration › troubleshooting
Troubleshooting - Material UI
// ...imports function ... /> </ThemeProvider> ); } export default App; CopyCopied(or $keyC) This error results from trying to access an empty theme....
🌐
GitHub
github.com › styled-components › styled-components › issues › 1932
Add theme object to styled-components without ThemeProvider · Issue #1932 · styled-components/styled-components
August 20, 2018 - import styled from 'styled-components' const theme = { color: 'blue' } const moddedStyled = withTheme(styled, theme) export default moddedStyled
Author   trevorwhealy
🌐
GitHub
github.com › mui › material-ui › issues › 16489
@material-ui/core has no exported member 'MuiThemeProvider' · Issue #16489 · mui/material-ui
July 4, 2019 - This is not a v0.x issue. I have searched the issues of this repository and believe that this is not a duplicate. Expected Behavior 🤔 MuiThemeProvider is exported by @matterial-ui/core or a related package Current Behavior 😯 Error is thr...
Author   mateja176
🌐
GitHub
github.com › styled-components › styled-components › issues › 2379
Empty theme context for 'external' components · Issue #2379 · styled-components/styled-components
February 11, 2019 - import React, { Component } from 'react'; import { ThemeProvider } from 'styled-components'; import Theme from '@namics-ui/theme-blue'; import Button from './Button'; import StyledButton from '@namics-ui/test'; class App extends Component { render() { return ( <ThemeProvider theme={Theme}> <div> <Button text="bla" /> // can access the theme props <StyledButton text="blabla" /> // cannot access the theme props </div> </ThemeProvider> ); } } export default App; import React, { ComponentType } from 'react'; import styled, { withTheme } from 'styled-components'; interface ButtonProps { text?: stri
Author   adriankremer
🌐
Emotion
emotion.sh › docs › typescript
Emotion – TypeScript
If you use our pragma implicitly (for example when using our @emotion/babel-preset-css-prop) we have a special file that can be imported once to add support for the css prop globally, for all components. Use it like this: /// <reference types="@emotion/react/types/css-prop" /> @emotion/styled works with TypeScript without any additional configuration.
Top answer
1 of 2
5

Weird that you're having any for your theme typing.

I'm doing it in a close but different way:

styled-component.d.ts

// import original module declarations
import 'styled-components';
import { ITheme } from './styles/theme';

// and extend them!
declare module 'styled-components' {
  // eslint-disable-next-line @typescript-eslint/no-empty-interface
  export interface DefaultTheme extends ITheme {}
}

I'm extending DefaultTheme with my ITheme object, which is something like that:

import {
  borderRadius,
  boxShadows,
  IBorderRadius,
  IBoxShadows,
  ITransitions,
  IZIndexes,
  transitions,
  zIndexes,
} from './base';
import { colors, IColors } from './colors';
import { ISizes, sizes } from './sizes';

export interface ITheme {
  colors: IColors;
  sizes: ISizes;
  boxShadows: IBoxShadows;
  zIndexes: IZIndexes;
  borderRadius: IBorderRadius;
  transitions: ITransitions;
}

export const Theme: ITheme = {
  colors,
  sizes,
  boxShadows,
  zIndexes,
  borderRadius,
  transitions,
};

And I'm using <ThemeProvider> from import { ThemeProvider } from 'styled-components';

<ThemeProvider theme={Theme}>

I'm using nearly the same versions as you:

"styled-components": "^5.3.3",
"@types/styled-components": "^5.1.19",

And here is my tsconfig.json

{
  "compilerOptions": {
    "jsx": "react-jsx",
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "baseUrl": "src",
    "paths": {
      "~/*": ["./*"]
    }
  },
  "include": [
    "src"
  ]
}
2 of 2
1

In typescript, the type definition is very important.

1. theme

import {ThemeProvider} from 'styled-components';

<ThemeProvider theme={theme}>
   //Your children component here
</ThemeProvider>

for types

//./styled-components.d.ts

import themeVariables from '<//theme variables path here>';

type ThemeInterface = typeof themeVariables 

declare module "styled-components" {
  interface DefaultTheme extends ThemeInterface {}
}

//tsconfig.json
{
  "compilerOptions": {
    "includes": ["styled-components.d.ts"]
  }
}

After it, you can use the theme in the styled component

const SomeStyledComponent = styled.div`
   background-color: ${props => props.theme.backgroundColor};
`

2.<{ invertedColor: boolean }> issue

interface SomeComponentProps {
   invertedColor: boolean;
}

const SomeComponent = styled.div<SomeComponentProps>`
  color: ${props => (props.invertedColor ? props.theme.color.white : props.theme.color.dark)}
`
🌐
GitHub
github.com › mui › material-ui › issues › 30092
[ThemeProvider] not working from @mui/material/styles, but does from @mui/styles. · Issue #30092 · mui/material-ui
December 7, 2021 - If you are using the utilities from @mui/styles together with the @mui/material, you should replace the use of ThemeProvider from @mui/styles with the one exported from @mui/material/styles.
Author   RobTF
🌐
GitHub
github.com › styled-components › styled-components › issues › 2158
ThemeProvider and GlobalStyles in latest version 4 · Issue #2158 · styled-components/styled-components
October 25, 2018 - They run fine when I remove ThemeProvider (and <GlobalStyles />) <GlobalStyles /> needs to be wrapped inside a styled.X component for it to work with HMR / React Hot Loader. If it is moved outside HMR will not work.
Author   mhaagens
🌐
UNPKG
unpkg.com › browse › @types › styled-components@5.1.25 › index.d.ts
types/styled-components/index.d.ts
ert `target is StyledComponent<any, T>` instead, but that feels not type safe isStyledComponent: typeof isStyledComponent; ServerStyleSheet: typeof ServerStyleSheet; StyleSheetManager: typeof StyleSheetManager; } declare const styled: StyledInterface; export const css: ThemedCssFunction<DefaultTheme>; export type BaseWithThemeFnInterface<T extends object> = <C extends React.ComponentType<any>>( // this check is roundabout because the extends clause above would // not allow any component that accepts _more_ than theme as a prop component: React.ComponentProps<C> extends { theme?: T | undefined
🌐
Stack Overflow
stackoverflow.com › questions › 75283990 › published-styled-components-ui-library-does-not-have-access-to-extended-theme-ty
reactjs - Published styled-components UI library does not have access to extended theme types on the consumer side - Stack Overflow
January 30, 2023 - // styled.d.ts import {} from 'styled-components'; import type { MyThemeType } from 'my-external-package//theme'; // extend theme declare module 'styled-components' { // eslint-disable-next-line @typescript-eslint/no-empty-interface export interface DefaultTheme extends MyThemeType {} } // CustomThemeProvider.tsx import React, { createContext, useState, ReactNode, useContext } from 'react'; import { ThemeProvider } from 'styled-components'; import { lightTheme, darkTheme } from './theme'; const themes = { light: lightTheme, dark: darkTheme, }; type CustomThemeProviderProps = { children: ReactN
🌐
DEV Community
dev.to › aromanarguello › how-to-use-themes-in-styled-components-49h
How to use Themes in styled-components - DEV Community
November 26, 2022 - Finally, we export the theme. import React from "react"; import { ThemeProvider } from "styled-components"; const theme = { colors: { powderWhite: "#FFFDF9", persianGreen: "#06B49A", lightBlue: "#AFDBD2", onyx: "#36313D" }, fonts: ["sans-serif", "Roboto"], fontSizes: { small: "1em", medium: "2em", large: "3em" } }; const Theme = ({ children }) => ( <ThemeProvider theme={theme}>{children}</ThemeProvider> ); export default Theme;