Skip to content

Commit f3c7e62

Browse files
committed
Add strict to tsconfig.json
1 parent 03d0c61 commit f3c7e62

File tree

5 files changed

+24
-23
lines changed

5 files changed

+24
-23
lines changed

lib/contents.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @typedef ContentsOptions
1010
* @property {boolean} [tight=false] Whether to compile list-items tightly.
1111
* @property {boolean} [ordered=false] Whether to compile list-items as an ordered list, otherwise they are unordered.
12-
* @property {string} [prefix=null] Add a prefix to links to headings in the table of contents. Useful for example when later going from mdast to hast and sanitizing with `hast-util-sanitize`.
12+
* @property {string|null} [prefix=null] Add a prefix to links to headings in the table of contents. Useful for example when later going from mdast to hast and sanitizing with `hast-util-sanitize`.
1313
*/
1414

1515
import extend from 'extend'
@@ -97,7 +97,7 @@ function insert(entry, parent, settings) {
9797
entry.depth--
9898
insert(
9999
entry,
100-
// @ts-ignore It’s a `list`, we just checked.
100+
// @ts-expect-error It’s a `list`, we just checked.
101101
parent.children[parent.children.length - 1],
102102
settings
103103
)
@@ -157,20 +157,15 @@ function one(node) {
157157
node.type === 'footnote' ||
158158
node.type === 'footnoteReference'
159159
) {
160-
// @ts-ignore Looks like a parent.
160+
// @ts-expect-error Looks like a parent.
161161
return all(node.children)
162162
}
163163

164-
let copy = extend({}, node)
165-
if ('children' in copy) delete copy.children
166-
delete copy.position
167-
168-
copy = extend(true, {}, copy)
169-
170164
if ('children' in node) {
171-
// @ts-ignore Looks like a parent.
172-
copy.children = all(node.children)
165+
const {children, position, ...copy} = node
166+
return Object.assign(extend(true, {}, copy), {children: all(node.children)})
173167
}
174168

175-
return copy
169+
const {position, ...copy} = node
170+
return extend(true, {}, copy)
176171
}

lib/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
* @property {string} [heading] Heading to look for, wrapped in `new RegExp('^(' + value + ')$', 'i')`.
1010
*
1111
* @typedef Result
12-
* @property {number} index
13-
* @property {number} endIndex
14-
* @property {List} map
12+
* @property {number|null} index
13+
* @property {number|null} endIndex
14+
* @property {List|null} map
1515
*/
1616

1717
import {search} from './search.js'

lib/search.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const slugs = new Slugger()
3535
* Search a node for a toc.
3636
*
3737
* @param {Node} root
38-
* @param {RegExp} expression
38+
* @param {RegExp|null} expression
3939
* @param {SearchOptions} settings
4040
* @returns {SearchResult}
4141
*/
@@ -44,7 +44,7 @@ export function search(root, expression, settings) {
4444
const parents = convert(settings.parents || ((d) => d === root))
4545
/** @type {Array.<SearchEntry>} */
4646
const map = []
47-
/** @type {number} */
47+
/** @type {number|undefined} */
4848
let index
4949
/** @type {number} */
5050
let endIndex
@@ -60,7 +60,7 @@ export function search(root, expression, settings) {
6060
return {
6161
index: index || -1,
6262
// <sindresorhus/eslint-plugin-unicorn#980>
63-
// @ts-ignore Looks like a parent.
63+
// @ts-expect-error Looks like a parent.
6464
endIndex: index ? endIndex || root.children.length : -1, // eslint-disable-line unicorn/explicit-length-check
6565
map
6666
}
@@ -69,7 +69,7 @@ export function search(root, expression, settings) {
6969
function onheading(node, position, parent) {
7070
const value = toString(node, {includeImageAlt: false})
7171
/** @type {string} */
72-
// @ts-ignore `hProperties` from <https://github.com/syntax-tree/mdast-util-to-hast>
72+
// @ts-expect-error `hProperties` from <https://github.com/syntax-tree/mdast-util-to-hast>
7373
const id = node.data && node.data.hProperties && node.data.hProperties.id
7474
const slug = slugs.slug(id || value)
7575

@@ -78,14 +78,19 @@ export function search(root, expression, settings) {
7878
}
7979

8080
// Our opening heading.
81-
if (expression && !index && expression.test(value)) {
81+
if (position !== null && expression && !index && expression.test(value)) {
8282
index = position + 1
8383
opening = node
8484
return
8585
}
8686

8787
// Our closing heading.
88-
if (opening && !endIndex && node.depth <= opening.depth) {
88+
if (
89+
position !== null &&
90+
opening &&
91+
!endIndex &&
92+
node.depth <= opening.depth
93+
) {
8994
endIndex = position
9095
}
9196

test/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ test('mdast-util-toc', (t) => {
2727

2828
t.throws(
2929
() => {
30-
// @ts-ignore runtime.
30+
// @ts-expect-error runtime.
3131
toc()
3232
},
3333
/Cannot read property 'children' of undefined/,

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)