TypeScript rejects a custom prop or a theme key inside a styled-components template
Your error
error TS2339: Property 'colors' does not exist on type 'DefaultTheme'.1 more line it can showFix it fast
Most common cause, 1 of 4The styled component has no type argument for its custom prop
Declare the extra props as a type argument and give them a $ prefix.
import styled from 'styled-components';
const Button = styled.button<{ $primary?: boolean }>`
background: ${(props) => (props.$primary ? 'navy' : 'white')};
`;
export const Save = () => <Button $primary>Save</Button>;Short answer
In styled-components 6, a TS2339 error inside a template, naming a prop or theme key that TypeScript does not know, has two sources. When the type named starts with ExecutionContext, the custom prop has no type argument: write styled.button<{ $primary?: boolean }>. When it is DefaultTheme, that empty interface was never extended in a styled.d.ts file TypeScript loads.
Which cause do you have?
Run the type checker on its own and look at the type quoted at the end of each TS2339 line. A type that begins with ExecutionContext sends you to the first cause; DefaultTheme sends you to the other three.
npx tsc --noEmit 2>&1 | grep TS2339Then find the line you see in this list and open its fix:
- 1The styled component has no type argument for its custom prop
The quoted type begins with ExecutionContext & and the property is one you made up, such as primary or isActive - 2DefaultTheme was never extended
The quoted type is exactly 'DefaultTheme' and no file in the project declares an interface with that name - 3styled.d.ts has no top-level import, so it declares a new module
styled.d.ts exists and holds declare module 'styled-components', but it has no import or export line at the top - 4The declarations file sits outside tsconfig include
npx tsc --listFilesOnly does not print styled.d.ts
What does the error look like?
error TS2339: Property 'colors' does not exist on type 'DefaultTheme'.error TS2339: Property 'primary' does not exist on type 'ExecutionContext & …'
Cause 1 of 4
The styled component has no type argument for its custom prop
You seeThe quoted type begins with ExecutionContext & and the property is one you made up, such as primary or isActive
Check
TS2339 on a made-up prop inside a styled-components template means the component was declared without a type argument. Each interpolation function receives ExecutionContext plus the props of the tag or component being styled, so a prop that you invented is unknown to TypeScript. List styled declarations that have no angle brackets before the template.
grep -rnE "styled(\.[a-z]+|\([A-Za-z]+\))\`" srcFix
Declare the extra props as a type argument and give them a $ prefix. A $ prop is transient: styled-components reads it for styling but does not pass it on to the DOM element or to a component you wrapped. The same type argument works on styled(MyComponent).
import styled from 'styled-components';
const Button = styled.button<{ $primary?: boolean }>`
background: ${(props) => (props.$primary ? 'navy' : 'white')};
`;
export const Save = () => <Button $primary>Save</Button>;Verify
The type check finishes with no TS2339 line for that file.
npx tsc --noEmitConfirmed by styled-components.com
Cause 2 of 4
DefaultTheme was never extended
You seeThe quoted type is exactly 'DefaultTheme' and no file in the project declares an interface with that name
Check
TS2339 on props.theme.something means TypeScript sees the theme as DefaultTheme, which styled-components ships as an empty interface for you to fill in. Until a declarations file adds your keys, every theme property is unknown, even when ThemeProvider receives the right object at runtime.
grep -rn "interface DefaultTheme" --include="*.ts" --include="*.tsx" . --exclude-dir=node_modulesFix
Create styled.d.ts that imports the package and merges your keys into DefaultTheme, then type the theme object with it so missing keys fail at compile time.
// src/styled.d.ts
import 'styled-components';
declare module 'styled-components' {
export interface DefaultTheme {
borderRadius: string;
colors: { main: string; secondary: string };
}
}
// src/theme.ts
import type { DefaultTheme } from 'styled-components';
export const theme: DefaultTheme = {
borderRadius: '5px',
colors: { main: 'cyan', secondary: 'magenta' },
};Verify
Hovering props.theme.colors in the editor shows your keys, and the checker passes.
npx tsc --noEmitConfirmed by styled-components.com
Cause 3 of 4
styled.d.ts has no top-level import, so it declares a new module
You seestyled.d.ts exists and holds declare module 'styled-components', but it has no import or export line at the top
Check
The DefaultTheme TS2339 error can stay after you add a declarations file when that file has no top-level import or export. TypeScript can then read it as a script, and in a script the very same declare module block is an ambient module declaration rather than an augmentation, so nothing merges into the real package types.
head -n 3 src/styled.d.tsFix
Put the bare import of the package on the first line. That turns the file into a module, and its declare module block becomes an augmentation of the installed types.
// src/styled.d.ts, first line
import 'styled-components';Verify
Run the checker again; the theme keys now resolve and TS2339 is gone.
npx tsc --noEmitConfirmed by typescriptlang.org
Cause 4 of 4
The declarations file sits outside tsconfig include
You seenpx tsc --listFilesOnly does not print styled.d.ts
Check
A correct styled.d.ts still leaves DefaultTheme empty, and the TS2339 error in place, when tsconfig.json never loads it. The include patterns are resolved from the folder that holds tsconfig.json, so a file kept in the project root or in a types folder is skipped when include names only src.
npx tsc --listFilesOnly | grep styled.d.ts
grep -n -A3 "\"include\"" tsconfig.jsonFix
Move the file under a folder that include already covers, or add its path to include.
// tsconfig.json
{
"include": ["src", "types/styled.d.ts"]
}Verify
The file now appears in the list of program files, and the error is gone.
npx tsc --listFilesOnly | grep styled.d.tsConfirmed by typescriptlang.org
How do I stop it coming back?
- Uninstall @types/styled-components on version 6: the package ships its own types, and the community package (5.1.x) was written for older releases.
- Give every invented styling prop a $ name and a type argument in the same commit that adds it.
- Type the theme object as DefaultTheme so a missing key fails in tsc, not as undefined in the browser.
- Run tsc --noEmit in CI so a theme or prop type error fails the pull request.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: TaxiDex, QistLock, Taskvare.