Skip to content

Commit cf764a5

Browse files
committed
Add strict to tsconfig
1 parent 14b0af0 commit cf764a5

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@ export const remove =
4141
? true
4242
: options.cascade
4343

44-
return preorder(tree, null, null)
44+
return preorder(tree)
4545

4646
/**
4747
* Check and remove nodes recursively in preorder.
4848
* For each composite node, modify its children array in-place.
4949
*
5050
* @param {Node} node
51-
* @param {number|null} index
52-
* @param {Parent|null} parent
51+
* @param {number|undefined} [index]
52+
* @param {Parent|undefined} [parent]
5353
* @returns {Node|null}
5454
*/
5555
function preorder(node, index, parent) {
5656
/** @type {Array.<Node>} */
57-
// @ts-ignore looks like a parent.
57+
// @ts-expect-error looks like a parent.
5858
const children = node.children || empty
5959
let childIndex = -1
6060
let position = 0
@@ -66,7 +66,7 @@ export const remove =
6666
if (children.length > 0) {
6767
// Move all living children to the beginning of the children array.
6868
while (++childIndex < children.length) {
69-
// @ts-ignore looks like a parent.
69+
// @ts-expect-error looks like a parent.
7070
if (preorder(children[childIndex], childIndex, node)) {
7171
children[position++] = children[childIndex]
7272
}

test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ test('should return `null` if root node is removed', (t) => {
6262
test('should cascade-remove parent nodes', (t) => {
6363
const tree = u('root', [u('node', [u('leaf', '1')]), u('leaf', '2')])
6464
const children = tree.children
65-
// @ts-ignore it exists!
65+
// @ts-expect-error it exists!
6666
const first = children[0].children[0]
6767
const last = children[1]
6868

@@ -117,19 +117,11 @@ test('should support type tests', (t) => {
117117
test('should support function tests', (t) => {
118118
const tree = u('node', [u('node', [u('leaf', '1')]), u('leaf', '2')])
119119

120-
remove(tree, {cascade: false}, test)
120+
remove(tree, {cascade: false}, (node) => literal(node) && node.value === '1')
121121

122122
t.deepEqual(tree, u('node', [u('node', []), u('leaf', '2')]))
123123

124124
t.end()
125-
126-
/**
127-
* @param {Literal} node
128-
* @returns {boolean}
129-
*/
130-
function test(node) {
131-
return node.value === '1'
132-
}
133125
})
134126

135127
test('opts.cascade = true', (t) => {
@@ -146,7 +138,7 @@ test('opts.cascade = false', (t) => {
146138
const tree = u('root', [u('node', [u('leaf', '1')]), u('leaf', '2')])
147139
const siblings = tree.children
148140
const node = siblings[0]
149-
// @ts-ignore it exists!
141+
// @ts-expect-error it exists!
150142
const children = node.children
151143

152144
const next = remove(tree, {cascade: false}, 'leaf')
@@ -155,7 +147,7 @@ test('opts.cascade = false', (t) => {
155147
t.deepEqual(tree, u('root', [u('node', [])]))
156148
t.equal(tree.children, siblings)
157149
t.equal(tree.children[0], node)
158-
// @ts-ignore it exists!
150+
// @ts-expect-error it exists!
159151
t.equal(tree.children[0].children, children)
160152

161153
t.end()
@@ -179,3 +171,11 @@ test('example from readme', (t) => {
179171

180172
t.end()
181173
})
174+
175+
/**
176+
* @param {Node} node
177+
* @returns {node is Literal}
178+
*/
179+
function literal(node) {
180+
return 'value' in node
181+
}

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"declaration": true,
1111
"emitDeclarationOnly": true,
1212
"allowSyntheticDefaultImports": true,
13-
"skipLibCheck": true
13+
"skipLibCheck": true,
14+
"strict": true
1415
}
1516
}

0 commit comments

Comments
 (0)