Skip to content

Commit 6ef3933

Browse files
Fix to improve plugin, plugin tuples with boolean options
Closes GH-148. Reviewed-by: Titus Wormer <tituswormer@gmail.com>
1 parent b8fe5ec commit 6ef3933

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

types/index.d.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export interface Processor<P = Settings> extends FrozenProcessor<P> {
3636
* @typeParam S Plugin settings
3737
*/
3838
use<S extends any[] = [Settings?]>(
39-
pluginTuple: PluginTuple<S, P>
39+
pluginTuple: PluginTuple<S, P> | [Plugin<S, P>, boolean]
4040
): Processor<P>
4141

4242
/**
@@ -221,10 +221,7 @@ export interface FrozenProcessor<P = Settings> {
221221
* @typeParam P Processor settings
222222
* @returns Optional Transformer.
223223
*/
224-
export type Plugin<
225-
S extends any[] = [Settings?],
226-
P = Settings
227-
> = Attacher<S, P>
224+
export type Plugin<S extends any[] = [Settings?], P = Settings> = Attacher<S, P>
228225

229226
/**
230227
* Configuration passed to a Plugin or Processor
@@ -259,10 +256,10 @@ export interface ProcessorSettings<P = Settings> {
259256
* @typeParam S Plugin settings
260257
* @typeParam P Processor settings
261258
*/
262-
export type PluginTuple<
263-
S extends any[] = [Settings?],
264-
P = Settings
265-
> = [Plugin<S, P>, ...S]
259+
export type PluginTuple<S extends any[] = [Settings?], P = Settings> = [
260+
Plugin<S, P>,
261+
...S
262+
]
266263

267264
/**
268265
* A union of the different ways to add plugins to unified

types/unified-tests.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ processor.use([
7979
])
8080
processor.use(plugin, true)
8181
processor.use(plugin, false)
82+
processor.use([plugin, true])
83+
processor.use([plugin, false])
8284
processor.use([
8385
[plugin, true],
8486
[plugin, false]
@@ -124,6 +126,14 @@ processor.use([typedPlugin, typedSetting])
124126
processor.use([typedPlugin, typedSetting, settings])
125127
// $ExpectError
126128
processor.use([typedPlugin, settings])
129+
processor.use(typedPlugin, true)
130+
processor.use(typedPlugin, false)
131+
processor.use([typedPlugin, true])
132+
processor.use([typedPlugin, false])
133+
processor.use([
134+
[typedPlugin, true],
135+
[typedPlugin, false]
136+
])
127137

128138
processor.use(implicitlyTypedPlugin)
129139
processor.use(implicitlyTypedPlugin).use(implicitlyTypedPlugin)

0 commit comments

Comments
 (0)