-
-
Notifications
You must be signed in to change notification settings - Fork 86
Description
π Bug Report
Description
When using extendTailwindMerge to extend theme with custom colors and spacing, TypeScript throws compilation errors during build, even though the configuration works correctly in development mode.
Environment
- tailwind-merge version: 2.6.0
- TypeScript version: 5.x
- Next.js version: 15.3.2
- tailwindcss version: 3.x
- Build tool: Next.js build
- OS: Windows 11
Steps to Reproduce
- Create a
tailwind-mergeconfiguration with extended theme:
import { extendTailwindMerge } from "tailwind-merge";
const twMerge = extendTailwindMerge({
extend: {
theme: {
colors: [
"primary",
"tin-grey",
"lead-grey",
"blue-grey",
"state",
"error",
"warning",
"success",
"selected",
],
},
},
});- Run production build:
npm run build
Expected Behavior
The build should complete successfully without TypeScript errors, as the configuration is valid according to the documentation.
Actual Behavior
Build fails with TypeScript compilation error: Object literal may only specify known properties, but 'colors' does not exist in type 'Partial<ThemeObject>'. Did you mean to write 'color'?
Additional Context
- Development mode works fine - no errors during
npm run dev - Build mode fails - TypeScript strict checking during production build
- The error alternates between suggesting
colorsvscolordepending on which one is used - This appears to be a TypeScript definition issue where the theme extension types don't match the actual runtime behavior
Workaround Found
Instead of extending theme, override existing classGroups directly:
const twMerge = extendTailwindMerge({
extend: {
classGroups: {
// Override existing groups instead of extending theme
"bg-color": ["primary", "tin-grey", "lead-grey", "blue-grey", "state", "error", "warning", "success", "selected"],
"text-color": ["primary", "tin-grey", "lead-grey", "blue-grey", "state", "error", "warning", "success", "selected"],
},
},
});Questions
- Is extending theme via
theme.colorsofficially supported? - Should the TypeScript definitions be updated to properly support theme extension?
- Is the workaround above the recommended approach for adding custom theme values?
Related Issues
This seems related to broader TypeScript compatibility issues with theme configuration, similar to:
- Various Stack Overflow discussions about TailwindCSS + TypeScript type issues
Would appreciate clarification on the correct approach for extending themes with TypeScript support. Thank you! π