From 8b02a1342bd9b7746fc74d18fc6d9984b6ff7dd9 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Sun, 22 May 2022 01:25:27 +0200 Subject: [PATCH 1/2] improve types of the `tailwindcss/plugin` This also exposes/types the `plugin.withOptions` as described here: https://tailwindcss.com/docs/plugins#exposing-options --- plugin.d.ts | 15 ++++++++++----- types/config.d.ts | 6 +++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/plugin.d.ts b/plugin.d.ts index f78aad764505..07e1e20ec582 100644 --- a/plugin.d.ts +++ b/plugin.d.ts @@ -1,6 +1,11 @@ import type { Config, PluginCreator } from './types/config' -declare function createPlugin( - plugin: PluginCreator, - config?: Config -): { handler: PluginCreator; config?: Config } -export = createPlugin +type Plugin = { + withOptions( + plugin: (options: T) => PluginCreator, + config?: (options: T) => Config + ): { (options: T): { handler: PluginCreator; config?: Config }; __isOptionsFunction: true } + (plugin: PluginCreator, config?: Config): { handler: PluginCreator; config?: Config } +} + +declare const plugin: Plugin +export = plugin diff --git a/types/config.d.ts b/types/config.d.ts index c7adb70dadc8..d3dd1c451e7e 100644 --- a/types/config.d.ts +++ b/types/config.d.ts @@ -297,7 +297,11 @@ export interface PluginAPI { e: (className: string) => string } export type PluginCreator = (api: PluginAPI) => void -export type PluginsConfig = (PluginCreator | { handler: PluginCreator; config?: Config })[] +export type PluginsConfig = ( + | PluginCreator + | { handler: PluginCreator; config?: Config } + | { (options: any): { handler: PluginCreator; config?: Config }; __isOptionsFunction: true } +)[] // Top level config related interface RequiredConfig { From bab7bc595724e830b1f6356e5c701df54c35ba04 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Sun, 22 May 2022 01:30:33 +0200 Subject: [PATCH 2/2] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca3c9d8cc011..5552afebb5cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Error when registering an invalid custom variant ([#8345](https://github.com/tailwindlabs/tailwindcss/pull/8345)) - Create tailwind.config.cjs file in ESM package when running init ([#8363](https://github.com/tailwindlabs/tailwindcss/pull/8363)) - Fix `matchVariants` that use at-rules and placeholders ([#8392](https://github.com/tailwindlabs/tailwindcss/pull/8392)) +- Improve types of the `tailwindcss/plugin` ([#8400](https://github.com/tailwindlabs/tailwindcss/pull/8400)) ### Changed