1
- // Minimum TypeScript Version: 3.4
1
+ // Minimum TypeScript Version: 3.8
2
2
3
3
import { Transformer } from 'unified'
4
4
import { Prefix , CreateElementLike } from 'hast-to-hyperscript'
@@ -7,14 +7,20 @@ import {Node} from 'unist'
7
7
declare namespace rehypeReact {
8
8
type FragmentLike < T > = ( props : any ) => T | null
9
9
10
- interface ComponentProps {
11
- [ prop : string ] : unknown
12
- node ?: Node
10
+ type ComponentPropsWithoutNode = Record < string , unknown >
11
+
12
+ interface ComponentPropsWithNode extends ComponentPropsWithoutNode {
13
+ node : Node
13
14
}
14
15
15
- type ComponentLike < T > = ( props : ComponentProps ) => T | null
16
+ type ComponentProps = ComponentPropsWithoutNode | ComponentPropsWithNode
17
+
18
+ type ComponentLike <
19
+ T ,
20
+ P extends ComponentPropsWithoutNode = ComponentPropsWithoutNode
21
+ > = ( props : P ) => T | null
16
22
17
- interface Options < H extends CreateElementLike > {
23
+ interface SharedOptions < H extends CreateElementLike > {
18
24
/**
19
25
* How to create elements or components.
20
26
* You should typically pass `React.createElement`
@@ -27,25 +33,37 @@ declare namespace rehypeReact {
27
33
*/
28
34
Fragment ?: FragmentLike < ReturnType < H > >
29
35
30
- /**
31
- * Override default elements (such as `<a>`, `<p>`, etcetera) by passing an object mapping tag names to components
32
- */
33
- components ?: Record < string , ComponentLike < ReturnType < H > > >
34
-
35
36
/**
36
37
* React key prefix
37
38
*
38
39
* @defaultValue 'h-'
39
40
*/
40
41
prefix ?: Prefix
41
-
42
- /**
43
- * Expose HAST Node objects to `node` prop of react components
44
- *
45
- * @defaultValue false
46
- */
47
- passNode ?: boolean
48
42
}
43
+
44
+ type ComponentOptions < H extends CreateElementLike > =
45
+ | {
46
+ /**
47
+ * Override default elements (such as `<a>`, `<p>`, etcetera) by passing an object mapping tag names to components
48
+ */
49
+ components ?: Record <
50
+ string ,
51
+ ComponentLike < ReturnType < H > , ComponentPropsWithNode >
52
+ >
53
+ /**
54
+ * Expose HAST Node objects to `node` prop of react components
55
+ *
56
+ * @defaultValue false
57
+ */
58
+ passNode : true
59
+ }
60
+ | {
61
+ components ?: Record < string , ComponentLike < ReturnType < H > > >
62
+ passNode ?: false
63
+ }
64
+
65
+ type Options < H extends CreateElementLike > = SharedOptions < H > &
66
+ ComponentOptions < H >
49
67
}
50
68
51
69
/**
0 commit comments