Skip to content

Commit 75347a5

Browse files
committed
Update tsconfig.json
1 parent f54c3fe commit 75347a5

File tree

4 files changed

+48
-44
lines changed

4 files changed

+48
-44
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ export function map(tree, mapFunction) {
2626
// @ts-expect-error Looks like a children.
2727
return preorder(tree, null, null)
2828

29-
/** @type {import('./complex-types').MapFunction<Tree>} */
29+
/** @type {import('./complex-types.js').MapFunction<Tree>} */
3030
function preorder(node, index, parent) {
3131
var newNode = Object.assign({}, mapFunction(node, index, parent))
3232

3333
if ('children' in node) {
3434
// @ts-expect-error Looks like a parent.
3535
newNode.children = node.children.map(function (
36-
/** @type {import('./complex-types').InclusiveDescendant<Tree>} */ child,
36+
/** @type {import('./complex-types.js').InclusiveDescendant<Tree>} */ child,
3737
/** @type {number} */ index
3838
) {
3939
return preorder(child, index, node)

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
"prettier": "^2.0.0",
4545
"remark-cli": "^11.0.0",
4646
"remark-preset-wooorm": "^9.0.0",
47-
"rimraf": "^3.0.0",
4847
"tape": "^5.0.0",
4948
"type-coverage": "^2.0.0",
5049
"typescript": "^4.0.0",
@@ -53,10 +52,10 @@
5352
},
5453
"scripts": {
5554
"prepack": "npm run build && npm run format",
56-
"build": "rimraf \"{index,test}.d.ts\" && tsc && type-coverage",
55+
"build": "tsc --build --clean && tsc --build && type-coverage",
5756
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
58-
"test-api": "node test.js",
59-
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
57+
"test-api": "node --conditions development test.js",
58+
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
6059
"test": "npm run build && npm run format && npm run test-coverage"
6160
},
6261
"prettier": {

test.js

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,33 @@ import {u} from 'unist-builder'
1010
import {map} from './index.js'
1111

1212
test('unist-util-map', function (t) {
13+
/** @type {Root} */
14+
const rootA = u('root', [u('node', [u('leaf', '1')]), u('leaf', '2')])
1315
t.deepEqual(
14-
map(u('root', [u('node', [u('leaf', '1')]), u('leaf', '2')]), changeLeaf),
16+
map(rootA, changeLeaf),
1517
u('root', [u('node', [u('leaf', 'CHANGED')]), u('leaf', 'CHANGED')]),
1618
'should map the specified node'
1719
)
1820

21+
/** @type {Root} */
22+
const rootB = {
23+
type: 'root',
24+
children: [
25+
{type: 'node', children: [{type: 'leaf', value: '1'}]},
26+
{type: 'leaf', value: '2'}
27+
]
28+
}
1929
t.deepEqual(
20-
map(
21-
/** @type {Root} */
22-
({
23-
type: 'root',
24-
children: [
25-
{type: 'node', children: [{type: 'leaf', value: '1'}]},
26-
{type: 'leaf', value: '2'}
27-
]
28-
}),
29-
changeLeaf
30-
),
30+
map(rootB, changeLeaf),
3131
u('root', [u('node', [u('leaf', 'CHANGED')]), u('leaf', 'CHANGED')]),
3232
'should map the specified node'
3333
)
3434

35+
/** @type {Root} */
36+
const rootC = u('root', [u('node', [u('leaf', '1')]), u('leaf', '2')])
3537
t.deepEqual(
36-
map(u('root', [u('node', [u('leaf', '1')]), u('leaf', '2')]), nullLeaf),
38+
// @ts-expect-error: invalid:
39+
map(rootC, nullLeaf),
3740
// @ts-expect-error: not valid but tested anyway.
3841
u('root', [u('node', [{}]), {}]),
3942
'should work when retuning an empty object'
@@ -66,23 +69,23 @@ test('unist-util-map', function (t) {
6669
? Object.assign({}, node, {value: 'CHANGED'})
6770
: node
6871
}
72+
})
6973

70-
/**
71-
* @param {AnyNode} node
72-
* @returns {AnyNode?}
73-
*/
74-
function nullLeaf(node) {
75-
return node.type === 'leaf' ? null : node
76-
}
74+
/**
75+
* @param {AnyNode} node
76+
* @returns {Root | Node | null}
77+
*/
78+
function nullLeaf(node) {
79+
return node.type === 'leaf' ? null : node
80+
}
7781

78-
function addValue() {
79-
return {value: 'test'}
80-
}
82+
function addValue() {
83+
return {value: 'test'}
84+
}
8185

82-
/**
83-
* @type {import('./index.js').MapFunction<Root>}
84-
*/
85-
function asIs(node) {
86-
return node
87-
}
88-
})
86+
/**
87+
* @type {import('./index.js').MapFunction<Root>}
88+
*/
89+
function asIs(node) {
90+
return node
91+
}

tsconfig.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
{
2-
"include": ["*.js"],
2+
"include": ["**/*.js", "complex-types.d.ts"],
3+
"exclude": ["coverage/", "node_modules/"],
34
"compilerOptions": {
4-
"target": "ES2020",
5-
"lib": ["ES2020"],
6-
"module": "ES2020",
7-
"moduleResolution": "node",
8-
"allowJs": true,
95
"checkJs": true,
106
"declaration": true,
117
"emitDeclarationOnly": true,
12-
"allowSyntheticDefaultImports": true,
13-
"skipLibCheck": true
8+
"exactOptionalPropertyTypes": true,
9+
"forceConsistentCasingInFileNames": true,
10+
"lib": ["es2020"],
11+
"module": "node16",
12+
"newLine": "lf",
13+
"skipLibCheck": true,
14+
"strict": true,
15+
"target": "es2020"
1416
}
1517
}

0 commit comments

Comments
 (0)