Skip to content

Commit

Permalink
Improve types of the tailwindcss/plugin (#8400)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
RobinMalfait committed May 23, 2022
1 parent 8164185 commit 83b4811
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
15 changes: 10 additions & 5 deletions 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<T>(
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
6 changes: 5 additions & 1 deletion types/config.d.ts
Expand Up @@ -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 {
Expand Down

0 comments on commit 83b4811

Please sign in to comment.