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

Fix to improve plugin, plugin tuples with boolean options #148

Merged
merged 2 commits into from Jul 6, 2021
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
15 changes: 6 additions & 9 deletions types/index.d.ts
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
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