tailwindcss: Tailwind 3 broken TS types for config
What version of Tailwind CSS are you using?
3.0.1
What build tool (or framework if it abstracts the build tool) are you using?
Next.js 12.0.7
What version of Node.js are you using?
For example: v14.18.1
What browser are you using?
Chrome
What operating system are you using?
macOS
Describe your issue
Documentation says to do this to reference tailwind abstraction from JS:
import resolveConfig from 'tailwindcss/resolveConfig'
import tailwindConfig from './tailwind.config.js'
const fullConfig = resolveConfig(tailwindConfig)
fullConfig.theme.width[4]
// => '1rem'
fullConfig.theme.screens.md
// => '768px'
fullConfig.theme.boxShadow['2xl']
// => '0 25px 50px -12px rgba(0, 0, 0, 0.25)'
When I try to do this, I have the following errors in the latest version:
import { TailwindConfig } from 'tailwindcss/tailwind-config';
import resolveConfig from 'tailwindcss/resolveConfig'
import tailwindConfig from '../tailwind.config.js'
const fullConfig = resolveConfig(tailwindConfig as unknown as TailwindConfig)
fullConfig.theme.width[4]
// => TS7053: Element implicitly has an 'any' type because expression of type '4' can't be used to index type 'TailwindThemeValue'. Property '4' does not exist on type 'TailwindThemeValue'.
fullConfig.theme.screens.md
// => TS2339: Property 'md' does not exist on type 'TailwindThemeValue'. Property 'md' does not exist on type '(getters: { theme: any; negative: any; colors: any; breakpoints: any; }) => TailwindValues'
fullConfig.theme.boxShadow['2xl']
// => TS7053: Element implicitly has an 'any' type because expression of type '"2xl"' can't be used to index type 'TailwindThemeValue'. Property '2xl' does not exist on type 'TailwindThemeValue'.

Seems something wrong with types for the latest release. I use tailwind types to describe my components props, so it’s kind of critical to fix.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (4 by maintainers)
@sachinraja thanks for the link. It’s quite strange that such popular lib doesn’t have own integrated TS typings yet.
We have the same problem. Our temporary solution:
there is a more convenient solution than using any
For anyone coming to this thread for solutions in the future, now that the config file can be in typescript, using
satisfies Configshould resolve this issue, eg.This accomplishes 2 things:
Note that without
satisfiesyou could leave out theConfigtype entirely to get typescript to infer a specific type, but the default inference can get things wrong. For example, I had an error about my font size values, because it inferred that the value'2xs': ['0.625rem', '1rem']wasstring[]which isn’t assignable to[string, string].satisfiesallows it to narrow down the type of the array to match the expected tuple type.Thanks @misha-front that fixed worked. In the meantime I recommend reopening this issue so the missing types can be provided.