Skip to content

Commit 83b4811

Browse files
authored
Improve types of the tailwindcss/plugin (#8400)
* improve types of the `tailwindcss/plugin` This also exposes/types the `plugin.withOptions` as described here: https://tailwindcss.com/docs/plugins#exposing-options * update changelog
1 parent 8164185 commit 83b4811

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2424
- Error when registering an invalid custom variant ([#8345](https://github.com/tailwindlabs/tailwindcss/pull/8345))
2525
- Create tailwind.config.cjs file in ESM package when running init ([#8363](https://github.com/tailwindlabs/tailwindcss/pull/8363))
2626
- Fix `matchVariants` that use at-rules and placeholders ([#8392](https://github.com/tailwindlabs/tailwindcss/pull/8392))
27+
- Improve types of the `tailwindcss/plugin` ([#8400](https://github.com/tailwindlabs/tailwindcss/pull/8400))
2728

2829
### Changed
2930

plugin.d.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import type { Config, PluginCreator } from './types/config'
2-
declare function createPlugin(
3-
plugin: PluginCreator,
4-
config?: Config
5-
): { handler: PluginCreator; config?: Config }
6-
export = createPlugin
2+
type Plugin = {
3+
withOptions<T>(
4+
plugin: (options: T) => PluginCreator,
5+
config?: (options: T) => Config
6+
): { (options: T): { handler: PluginCreator; config?: Config }; __isOptionsFunction: true }
7+
(plugin: PluginCreator, config?: Config): { handler: PluginCreator; config?: Config }
8+
}
9+
10+
declare const plugin: Plugin
11+
export = plugin

types/config.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,11 @@ export interface PluginAPI {
297297
e: (className: string) => string
298298
}
299299
export type PluginCreator = (api: PluginAPI) => void
300-
export type PluginsConfig = (PluginCreator | { handler: PluginCreator; config?: Config })[]
300+
export type PluginsConfig = (
301+
| PluginCreator
302+
| { handler: PluginCreator; config?: Config }
303+
| { (options: any): { handler: PluginCreator; config?: Config }; __isOptionsFunction: true }
304+
)[]
301305

302306
// Top level config related
303307
interface RequiredConfig {

0 commit comments

Comments
 (0)