I'm importing the following code into my .tsx component:
import resolveConfig from 'tailwindcss/resolveConfig';
import tailwindConfig from '../../../tailwind.config.js';
const fullConfig = resolveConfig(tailwindConfig)
If I then reference fullConfig.theme.colors["blue"]["700"] I get an error saying:
Element implicitly has an 'any' type because expression of type '"blue"' can't be used to index type 'TailwindThemeColors'. Property 'blue' does not exist on type 'TailwindThemeColors'.
The Tailwind type definition for colors is:
export type TailwindColorValue = string | TailwindColorGroup | TailwindColorFunction;
export interface TailwindValuesColor {
readonly [key: string]: TailwindColorValue;
}
Since the type does not explicitly say that "blue" is a value and that it could be an object, that's the cause of the error (I think).
An additional problem I'm getting is an error in my tsconfig.json, because I'm importing a JS file.
Adding "exclude": ["tailwind.config.js"] doesn't solve the issue.
I'm pretty sure this is a Typescript issue more than a Tailwind one...
My questions are:
- How can I make Typescript aware of the "blue" property on the colors in my tailwind theme, and
- How can I stop the tsconfig error from importing the JS config?
Any help in resolving this would be hugely appreciated.