Skip to content

Commit 4bfd6c8

Browse files
authored
types: add support for boolean plugin options
Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com> Closes GH-145.
1 parent 45eb72e commit 4bfd6c8

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

types/index.d.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface Processor<P = Settings> extends FrozenProcessor<P> {
1717
* @typeParam S Plugin settings
1818
* @returns The processor on which use is called
1919
*/
20-
use<S extends any[] = [Settings?]>(
20+
use<S extends any[] = [(Settings | boolean)?]>(
2121
plugin: Plugin<S, P>,
2222
...settings: S
2323
): Processor<P>
@@ -221,7 +221,10 @@ export interface FrozenProcessor<P = Settings> {
221221
* @typeParam P Processor settings
222222
* @returns Optional Transformer.
223223
*/
224-
export type Plugin<S extends any[] = [Settings?], P = Settings> = Attacher<S, P>
224+
export type Plugin<
225+
S extends any[] = [(Settings | boolean)?],
226+
P = Settings
227+
> = Attacher<S, P>
225228

226229
/**
227230
* Configuration passed to a Plugin or Processor
@@ -256,10 +259,10 @@ export interface ProcessorSettings<P = Settings> {
256259
* @typeParam S Plugin settings
257260
* @typeParam P Processor settings
258261
*/
259-
export type PluginTuple<S extends any[] = [Settings?], P = Settings> = [
260-
Plugin<S, P>,
261-
...S
262-
]
262+
export type PluginTuple<
263+
S extends any[] = [(Settings | boolean)?],
264+
P = Settings
265+
> = [Plugin<S, P>, ...S]
263266

264267
/**
265268
* A union of the different ways to add plugins to unified

types/unified-tests.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ processor.use([
7777
[plugin, settings],
7878
[plugin, settings]
7979
])
80+
processor.use(plugin, true)
81+
processor.use(plugin, false)
82+
processor.use([
83+
[plugin, true],
84+
[plugin, false]
85+
])
8086

8187
processor.use(parserPlugin)
8288
processor.use(parserPlugin).use(parserPlugin)

0 commit comments

Comments
 (0)