File tree 3 files changed +40
-3
lines changed 3 files changed +40
-3
lines changed Original file line number Diff line number Diff line change
1
+ import { expectType } from 'tsd'
2
+ import type {
3
+ Delete ,
4
+ Emphasis ,
5
+ Link ,
6
+ LinkReference ,
7
+ Heading ,
8
+ PhrasingContent ,
9
+ Strong ,
10
+ Text
11
+ } from 'mdast'
12
+ import { map } from './index.js'
13
+
14
+ const text : Text = { type : 'text' , value : 'alpha' }
15
+ const heading : Heading = { type : 'heading' , depth : 1 , children : [ text ] }
16
+
17
+ // @ts -expect-error: tree needed.
18
+ map ( )
19
+
20
+ // @ts -expect-error: map function needed.
21
+ map ( heading )
22
+
23
+ map ( text , function ( node ) {
24
+ expectType < Text > ( node )
25
+ return node
26
+ } )
27
+
28
+ map ( heading , function ( node , index , parent ) {
29
+ expectType < Heading | PhrasingContent > ( node )
30
+ expectType < number | undefined > ( index )
31
+ expectType <
32
+ Delete | Emphasis | Link | Heading | LinkReference | Strong | undefined
33
+ > ( parent )
34
+ return node
35
+ } )
Original file line number Diff line number Diff line change 49
49
* Node type.
50
50
* @typedef {(
51
51
* (
52
- * node: Readonly< InclusiveDescendant<Tree> >,
52
+ * node: InclusiveDescendant<Tree>,
53
53
* index: number | undefined,
54
- * parent: Readonly< Extract<InclusiveDescendant<Tree>, UnistParent> > | undefined
54
+ * parent: Extract<InclusiveDescendant<Tree>, UnistParent> | undefined
55
55
* ) => Tree | InclusiveDescendant<Tree>
56
56
* )} MapFunction
57
57
* Function called with a node, its index, and its parent to produce a new
Original file line number Diff line number Diff line change 38
38
"@types/unist" : " ^3.0.0"
39
39
},
40
40
"devDependencies" : {
41
+ "@types/mdast" : " ^4.0.0" ,
41
42
"@types/node" : " ^20.0.0" ,
42
43
"c8" : " ^8.0.0" ,
43
44
"prettier" : " ^2.0.0" ,
44
45
"remark-cli" : " ^11.0.0" ,
45
46
"remark-preset-wooorm" : " ^9.0.0" ,
47
+ "tsd" : " ^0.28.0" ,
46
48
"type-coverage" : " ^2.0.0" ,
47
49
"typescript" : " ^5.0.0" ,
48
50
"unist-builder" : " ^4.0.0" ,
49
51
"xo" : " ^0.54.0"
50
52
},
51
53
"scripts" : {
52
54
"prepack" : " npm run build && npm run format" ,
53
- "build" : " tsc --build --clean && tsc --build && type-coverage" ,
55
+ "build" : " tsc --build --clean && tsc --build && tsd && type-coverage" ,
54
56
"format" : " remark . -qfo && prettier . -w --loglevel warn && xo --fix" ,
55
57
"test-api" : " node --conditions development test.js" ,
56
58
"test-coverage" : " c8 --100 --reporter lcov npm run test-api" ,
You can’t perform that action at this time.
0 commit comments