1
- // TypeScript Version: 3.0
1
+ // TypeScript Version: 3.4
2
2
3
3
import { Node } from 'unist'
4
4
import { VFile , VFileContents , VFileOptions } from 'vfile'
@@ -23,33 +23,29 @@ declare namespace unified {
23
23
*
24
24
* @param plugin unified plugin
25
25
* @param settings Configuration for plugin
26
- * @param extraSettings Additional configuration for plugin
27
26
* @typeParam S Plugin settings
28
- * @typeParam S2 Extra plugin settings
29
27
* @returns The processor on which use is invoked
30
28
*/
31
- use < S = Settings , S2 = undefined > (
32
- plugin : Plugin < S , S2 , P > ,
33
- settings ?: S ,
34
- extraSettings ?: S2
29
+ use < S extends any [ ] = [ Settings ?] > (
30
+ plugin : Plugin < S , P > ,
31
+ ...settings : S
35
32
) : Processor < P >
36
33
37
34
/**
38
35
* Configure the processor with a preset to use
39
36
*
40
37
* @param preset `Object` with an plugins (set to list), and/or an optional settings object
41
38
*/
42
- use ( preset : Preset < P > ) : Processor < P >
39
+ use < S extends any [ ] = [ Settings ? ] > ( preset : Preset < S , P > ) : Processor < P >
43
40
44
41
/**
45
42
* Configure using a tuple of plugin and setting(s)
46
43
*
47
44
* @param pluginTuple pairs, plugin and settings in an array
48
45
* @typeParam S Plugin settings
49
- * @typeParam S2 Extra plugin settings
50
46
*/
51
- use < S = Settings , S2 = Settings > (
52
- pluginTuple : PluginTuple < S , S2 , P >
47
+ use < S extends any [ ] = [ Settings ? ] > (
48
+ pluginTuple : PluginTuple < S , P >
53
49
) : Processor < P >
54
50
55
51
/**
@@ -214,13 +210,11 @@ declare namespace unified {
214
210
*
215
211
* @this Processor context object is set to the invoked on processor.
216
212
* @param settings Configuration
217
- * @param extraSettings Secondary configuration
218
213
* @typeParam S Plugin settings
219
- * @typeParam S2 Extra plugin settings
220
214
* @typeParam P Processor settings
221
215
* @returns Optional Transformer.
222
216
*/
223
- type Plugin < S = Settings , S2 = undefined , P = Settings > = Attacher < S , S2 , P >
217
+ type Plugin < S extends any [ ] = [ Settings ? ] , P = Settings > = Attacher < S , P >
224
218
225
219
/**
226
220
* Configuration passed to a Plugin or Processor
@@ -235,7 +229,7 @@ declare namespace unified {
235
229
*
236
230
* @typeParam P Processor settings
237
231
*/
238
- interface Preset < P = Settings > {
232
+ interface Preset < S = Settings , P = Settings > {
239
233
plugins : PluggableList < P >
240
234
settings ?: Settings
241
235
}
@@ -253,31 +247,35 @@ declare namespace unified {
253
247
* A pairing of a plugin with its settings
254
248
*
255
249
* @typeParam S Plugin settings
256
- * @typeParam S2 Extra plugin settings
257
250
* @typeParam P Processor settings
258
251
*/
259
- type PluginTuple < S = Settings , S2 = undefined , P = Settings > =
260
- | [ Plugin < S , undefined , P > , S ]
261
- | [ Plugin < S , S2 , P > , S , S2 ]
252
+ type PluginTuple < S extends any [ ] = [ Settings ?] , P = Settings > = [
253
+ Plugin < S , P > ,
254
+ /**
255
+ * NOTE: ideally this would be S instead of any[]
256
+ * As of TypeScript 3.5.2 generic tuples cannot be spread
257
+ * See: https://github.com/microsoft/TypeScript/issues/26113
258
+ */
259
+ ...any [ ]
260
+ ]
262
261
263
262
/**
264
263
* A union of the different ways to add plugins to unified
265
264
*
266
265
* @typeParam S Plugin settings
267
- * @typeParam S2 Extra plugin settings
268
266
* @typeParam P Processor settings
269
267
*/
270
- type Pluggable < S = Settings , S2 = undefined , P = Settings > =
271
- | Plugin < S , S2 , P >
272
- | Preset < P >
273
- | PluginTuple < S , S2 , P >
268
+ type Pluggable < S extends any [ ] = [ Settings ? ] , P = Settings > =
269
+ | Plugin < S , P >
270
+ | Preset < S , P >
271
+ | PluginTuple < S , P >
274
272
275
273
/**
276
274
* A list of plugins and presets
277
275
*
278
276
* @typeParam P Processor settings
279
277
*/
280
- type PluggableList < P = Settings > = Array < Pluggable < any , any , P > >
278
+ type PluggableList < P = Settings > = Array < Pluggable < [ any ? ] , P > >
281
279
282
280
/**
283
281
* An attacher is the thing passed to `use`.
@@ -287,14 +285,12 @@ declare namespace unified {
287
285
*
288
286
* @this Processor context object is set to the invoked on processor.
289
287
* @param settings Configuration
290
- * @param extraSettings Secondary configuration
291
288
* @typeParam S Plugin settings
292
- * @typeParam S2 Extra plugin settings
293
289
* @typeParam P Processor settings
294
290
* @returns Optional Transformer.
295
291
*/
296
- interface Attacher < S = Settings , S2 = undefined , P = Settings > {
297
- ( this : Processor < P > , settings ? : S , extraSettings ?: S2 ) : Transformer | void
292
+ interface Attacher < S extends any [ ] = [ Settings ? ] , P = Settings > {
293
+ ( this : Processor < P > , ... settings : S ) : Transformer | void
298
294
}
299
295
300
296
/**
0 commit comments