Skip to content

Commit

Permalink
Fix to improve plugin, plugin tuples with boolean options
Browse files Browse the repository at this point in the history
Closes GH-148.

Reviewed-by: Titus Wormer <tituswormer@gmail.com>
  • Loading branch information
ChristianMurphy authored Jul 6, 2021
1 parent b8fe5ec commit 6ef3933
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
15 changes: 6 additions & 9 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface Processor<P = Settings> extends FrozenProcessor<P> {
* @typeParam S Plugin settings
*/
use<S extends any[] = [Settings?]>(
pluginTuple: PluginTuple<S, P>
pluginTuple: PluginTuple<S, P> | [Plugin<S, P>, boolean]
): Processor<P>

/**
Expand Down Expand Up @@ -221,10 +221,7 @@ 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?], P = Settings> = Attacher<S, P>

/**
* Configuration passed to a Plugin or Processor
Expand Down Expand Up @@ -259,10 +256,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?], P = Settings> = [
Plugin<S, P>,
...S
]

/**
* A union of the different ways to add plugins to unified
Expand Down
10 changes: 10 additions & 0 deletions types/unified-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ processor.use([
])
processor.use(plugin, true)
processor.use(plugin, false)
processor.use([plugin, true])
processor.use([plugin, false])
processor.use([
[plugin, true],
[plugin, false]
Expand Down Expand Up @@ -124,6 +126,14 @@ processor.use([typedPlugin, typedSetting])
processor.use([typedPlugin, typedSetting, settings])
// $ExpectError
processor.use([typedPlugin, settings])
processor.use(typedPlugin, true)
processor.use(typedPlugin, false)
processor.use([typedPlugin, true])
processor.use([typedPlugin, false])
processor.use([
[typedPlugin, true],
[typedPlugin, false]
])

processor.use(implicitlyTypedPlugin)
processor.use(implicitlyTypedPlugin).use(implicitlyTypedPlugin)
Expand Down

0 comments on commit 6ef3933

Please sign in to comment.