Skip to content

Commit

Permalink
types: add support for boolean plugin options
Browse files Browse the repository at this point in the history
Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com>

Closes GH-145.
  • Loading branch information
wooorm authored Jul 4, 2021
1 parent 45eb72e commit 4bfd6c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
15 changes: 9 additions & 6 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface Processor<P = Settings> extends FrozenProcessor<P> {
* @typeParam S Plugin settings
* @returns The processor on which use is called
*/
use<S extends any[] = [Settings?]>(
use<S extends any[] = [(Settings | boolean)?]>(
plugin: Plugin<S, P>,
...settings: S
): Processor<P>
Expand Down Expand Up @@ -221,7 +221,10 @@ export interface FrozenProcessor<P = Settings> {
* @typeParam P Processor settings
* @returns Optional Transformer.
*/
export type Plugin<S extends any[] = [Settings?], P = Settings> = Attacher<S, P>
export type Plugin<
S extends any[] = [(Settings | boolean)?],
P = Settings
> = Attacher<S, P>

/**
* Configuration passed to a Plugin or Processor
Expand Down Expand Up @@ -256,10 +259,10 @@ export interface ProcessorSettings<P = Settings> {
* @typeParam S Plugin settings
* @typeParam P Processor settings
*/
export type PluginTuple<S extends any[] = [Settings?], P = Settings> = [
Plugin<S, P>,
...S
]
export type PluginTuple<
S extends any[] = [(Settings | boolean)?],
P = Settings
> = [Plugin<S, P>, ...S]

/**
* A union of the different ways to add plugins to unified
Expand Down
6 changes: 6 additions & 0 deletions types/unified-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ processor.use([
[plugin, settings],
[plugin, settings]
])
processor.use(plugin, true)
processor.use(plugin, false)
processor.use([
[plugin, true],
[plugin, false]
])

processor.use(parserPlugin)
processor.use(parserPlugin).use(parserPlugin)
Expand Down

0 comments on commit 4bfd6c8

Please sign in to comment.