File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -375,6 +375,31 @@ The remark organization and the unified collective as a whole is fully typed
375
375
with [ TypeScript] [ ] .
376
376
Types for mdast are available in [ ` @types/mdast ` ] [ types-mdast ] .
377
377
378
+ For TypeScript to work, it is particularly important to type your plugins
379
+ correctly.
380
+ We strongly recommend using the ` Plugin ` type from ` unified ` with its generics
381
+ and to use the node types for the syntax trees provided by ` @types/mdast ` .
382
+
383
+ ``` js
384
+ /**
385
+ * @typedef {import('mdast').Root} Root
386
+ *
387
+ * @typedef Options
388
+ * Configuration (optional).
389
+ * @property {boolean} [someField]
390
+ * Some option.
391
+ */
392
+
393
+ // To type options and that the it works with `mdast`:
394
+ /** @type {import('unified').Plugin<[Options?], Root>} */
395
+ export function myRemarkPluginAcceptingOptions (options ) {
396
+ // `options` is `Options?`.
397
+ return function (tree , file ) {
398
+ // `tree` is `Root`.
399
+ }
400
+ }
401
+ ```
402
+
378
403
## Compatibility
379
404
380
405
Projects maintained by the unified collective are compatible with all maintained
You can’t perform that action at this time.
0 commit comments