Skip to content

Commit 4a74543

Browse files
authored
Add type annotations to the tailwind.config.js file (#8493)
* add type annotation to the config by default * use `@type {import('tailwindcss').Config}` instead
1 parent 64b4e6d commit 4a74543

File tree

6 files changed

+4
-60
lines changed

6 files changed

+4
-60
lines changed

integrations/tailwindcss-cli/tests/cli.test.js

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -441,46 +441,6 @@ describe('Init command', () => {
441441
// multiple keys in `theme` exists. However it loads `tailwindcss/colors`
442442
// which doesn't exists in this context.
443443
expect((await readOutputFile('../full.config.js')).split('\n').length).toBeGreaterThan(50)
444-
445-
expect(await readOutputFile('../full.config.js')).not.toContain(
446-
`/** @type {import('tailwindcss/types').Config} */`
447-
)
448-
})
449-
450-
test('--types', async () => {
451-
cleanupFile('simple.config.js')
452-
453-
let { combined } = await $(`${EXECUTABLE} init simple.config.js --types`)
454-
455-
expect(combined).toMatchInlineSnapshot(`
456-
"
457-
Created Tailwind CSS config file: simple.config.js
458-
"
459-
`)
460-
461-
expect(await readOutputFile('../simple.config.js')).toContain(
462-
`/** @type {import('tailwindcss/types').Config} */`
463-
)
464-
})
465-
466-
test('--full --types', async () => {
467-
cleanupFile('full.config.js')
468-
469-
let { combined } = await $(`${EXECUTABLE} init full.config.js --full --types`)
470-
471-
expect(combined).toMatchInlineSnapshot(`
472-
"
473-
Created Tailwind CSS config file: full.config.js
474-
"
475-
`)
476-
477-
// Not a clean way to test this. We could require the file and verify that
478-
// multiple keys in `theme` exists. However it loads `tailwindcss/colors`
479-
// which doesn't exists in this context.
480-
expect((await readOutputFile('../full.config.js')).split('\n').length).toBeGreaterThan(50)
481-
expect(await readOutputFile('../full.config.js')).toContain(
482-
`/** @type {import('tailwindcss/types').Config} */`
483-
)
484444
})
485445

486446
test('--postcss', async () => {
@@ -513,7 +473,6 @@ describe('Init command', () => {
513473
Options:
514474
-f, --full Initialize a full \`tailwind.config.js\` file
515475
-p, --postcss Initialize a \`postcss.config.js\` file
516-
--types Add TypeScript types for the \`tailwind.config.js\` file
517476
-h, --help Display usage information
518477
`)
519478
)
@@ -542,7 +501,6 @@ describe('Init command', () => {
542501
Options:
543502
-f, --full Initialize a full \`tailwind.config.cjs\` file
544503
-p, --postcss Initialize a \`postcss.config.cjs\` file
545-
--types Add TypeScript types for the \`tailwind.config.cjs\` file
546504
-h, --help Display usage information
547505
`)
548506
)
@@ -576,10 +534,6 @@ describe('Init command', () => {
576534
// Not a clean way to test this.
577535
expect(await readOutputFile('../tailwind.config.cjs')).toContain('module.exports =')
578536

579-
expect(await readOutputFile('../tailwind.config.cjs')).not.toContain(
580-
`/** @type {import('tailwindcss/types').Config} */`
581-
)
582-
583537
await writeInputFile('../package.json', pkg)
584538
})
585539
})

src/cli.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,6 @@ let commands = {
183183
args: {
184184
'--full': { type: Boolean, description: `Initialize a full \`${configs.tailwind}\` file` },
185185
'--postcss': { type: Boolean, description: `Initialize a \`${configs.postcss}\` file` },
186-
'--types': {
187-
type: Boolean,
188-
description: `Add TypeScript types for the \`${configs.tailwind}\` file`,
189-
},
190186
'-f': '--full',
191187
'-p': '--postcss',
192188
},
@@ -245,7 +241,7 @@ if (
245241
help({
246242
usage: [
247243
'tailwindcss [--input input.css] [--output output.css] [--watch] [options...]',
248-
'tailwindcss init [--full] [--postcss] [--types] [options...]',
244+
'tailwindcss init [--full] [--postcss] [options...]',
249245
],
250246
commands: Object.keys(commands)
251247
.filter((command) => command !== 'build')
@@ -372,13 +368,6 @@ function init() {
372368
'utf8'
373369
)
374370

375-
if (args['--types']) {
376-
let typesHeading = "/** @type {import('tailwindcss/types').Config} */"
377-
stubFile =
378-
stubFile.replace(`module.exports = `, `${typesHeading}\nconst config = `) +
379-
'\nmodule.exports = config'
380-
}
381-
382371
// Change colors import
383372
stubFile = stubFile.replace('../colors', 'tailwindcss/colors')
384373

stubs/defaultConfig.stub.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** @type {import('tailwindcss').Config} */
12
module.exports = {
23
content: [],
34
presets: [],

stubs/simpleConfig.stub.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** @type {import('tailwindcss').Config} */
12
module.exports = {
23
content: [],
34
theme: {

types.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
declare namespace tailwindcss {}
1+
export type { Config } from './config.d'

0 commit comments

Comments
 (0)