Skip to content
Discussion options

You must be logged in to vote

In a TypeScript monorepo, DefaultTheme module augmentation is global — all packages share the same augmented type. This is a TypeScript limitation, not a styled-components one.

Solutions:

  1. Shared theme type: Define one DefaultTheme augmentation in a shared package that all apps use. Each app can then provide different values conforming to the same shape.

  2. Per-package tsconfig: Ensure each package has its own tsconfig.json with a distinct rootDir and doesn't include declaration files from sibling packages.

  3. Generic wrapper: Instead of augmenting DefaultTheme, use a generic wrapper that types the theme per-component:

const themed = <T extends object>(fn: (theme: T) => string) => fn;

Op…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@benoitdeziel
Comment options

@sleepyArpan
Comment options

@benoitdeziel
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by quantizor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants