Skip to content

Commit

Permalink
improve types of the tailwindcss/plugin
Browse files Browse the repository at this point in the history
This also exposes/types the `plugin.withOptions` as described here: https://tailwindcss.com/docs/plugins#exposing-options
  • Loading branch information
RobinMalfait committed May 23, 2022
1 parent 8164185 commit 8b02a13
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
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 8b02a13

Please sign in to comment.