Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve types of the tailwindcss/plugin #8400

Merged
merged 2 commits into from May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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