Skip to content

Commit 6ccc003

Browse files
committed
Remove some unneeded ts-expect-errors
1 parent 6819e55 commit 6ccc003

File tree

10 files changed

+79
-53
lines changed

10 files changed

+79
-53
lines changed

docs/_asset/editor.jsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,9 +662,7 @@ function cleanUnistNode(node) {
662662
*/
663663
function removeFromEstree(node) {
664664
delete node.loc
665-
// @ts-expect-error: this field is added by acorn.
666665
delete node.start
667-
// @ts-expect-error: this field is added by acorn.
668666
delete node.end
669667
delete node.range
670668
}

docs/docs/getting-started.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ for more info.
454454
* @returns {unknown}
455455
*/
456456
function compiler(tree) {
457-
// @ts-expect-error TS2349: This expression *is* callable, `estreeToBabel` types are wrong.
457+
// @ts-expect-error: TS2349: This expression *is* callable, `estreeToBabel` types are wrong.
458458
return estreeToBabel(tree)
459459
}
460460
}
@@ -526,7 +526,7 @@ for more info.
526526
* @returns {unknown}
527527
*/
528528
function compiler(tree) {
529-
// @ts-expect-error TS2349: This expression *is* callable, `estreeToBabel` types are wrong.
529+
// @ts-expect-error: TS2349: This expression *is* callable, `estreeToBabel` types are wrong.
530530
return estreeToBabel(tree)
531531
}
532532
}

packages/mdx/lib/core.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* @import {Options as RemarkRehypeOptions} from 'remark-rehype'
66
* @import {SourceMapGenerator} from 'source-map'
77
* @import {PluggableList, Processor} from 'unified'
8+
* @import {Node} from 'unist'
89
*/
910

1011
/**
@@ -217,6 +218,8 @@ export function createProcessor(options) {
217218
}
218219

219220
pipeline
221+
// @ts-expect-error: `Program` is close enough to a `Node`,
222+
// but type inference has trouble with it and bridges.
220223
.use(rehypeRecma, settings)
221224
.use(recmaDocument, settings)
222225
.use(recmaJsxRewrite, settings)
@@ -225,8 +228,10 @@ export function createProcessor(options) {
225228
pipeline.use(recmaJsxBuild, settings)
226229
}
227230

231+
// @ts-expect-error: `Program` is close enough to a `Node`,
232+
// but type inference has trouble with it and bridges.
228233
pipeline.use(recmaStringify, settings).use(settings.recmaPlugins || [])
229234

230-
// @ts-expect-error: we added plugins with if-checks, which TS doesn’t get.
235+
// @ts-expect-error: TS doesn’t get the plugins we added with if-statements.
231236
return pipeline
232237
}

packages/mdx/lib/plugin/recma-stringify.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @import {Program} from 'estree-jsx'
3-
* @import {Plugin, Processor} from 'unified'
3+
* @import {Processor} from 'unified'
44
* @import {VFile} from 'vfile'
55
* @import {ProcessorOptions} from '../core.js'
66
*/
@@ -10,18 +10,15 @@ import {jsx, toJs} from 'estree-util-to-js'
1010
/**
1111
* Serialize an esast (estree) program to JavaScript.
1212
*
13-
* @type {Plugin<[Readonly<ProcessorOptions>], Program, string>}
13+
* @this {Processor<undefined, undefined, undefined, Program, string>}
14+
* Processor.
15+
* @param {Readonly<ProcessorOptions>} options
16+
* Configuration.
1417
*/
1518
export function recmaStringify(options) {
16-
// eslint-disable-next-line unicorn/no-this-assignment
17-
const self =
18-
// @ts-expect-error: TS is wrong about `this`.
19-
/** @type {Processor<undefined, undefined, undefined, Program, string>} */ (
20-
this
21-
)
2219
const {SourceMapGenerator} = options
2320

24-
self.compiler = compiler
21+
this.compiler = compiler
2522

2623
/**
2724
* @param {Program} tree

packages/mdx/lib/types.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type {Program as EstreeProgram} from 'estree'
12
import type {Data as UnistData} from 'unist'
23

34
interface EsastData extends UnistData {
@@ -63,3 +64,9 @@ declare module 'mdast-util-mdx-jsx' {
6364
_mdxExplicitJsx?: boolean | null | undefined
6465
}
6566
}
67+
68+
declare module 'unified' {
69+
interface CompileResultMap {
70+
EstreeProgram: EstreeProgram
71+
}
72+
}

packages/mdx/lib/util/estree-util-create.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
*/
1616
export function create(from, to) {
1717
/** @type {Array<keyof Node>} */
18-
// @ts-expect-error: `start`, `end`, `comments` are custom Acorn fields.
19-
const fields = ['start', 'end', 'loc', 'range', 'comments']
18+
const fields = ['start', 'end', 'loc', 'range']
2019
let index = -1
2120

2221
while (++index < fields.length) {

packages/preact/test/index.jsx

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ test('@mdx-js/preact', async function (t) {
3737
render(
3838
<MDXProvider
3939
components={{
40-
// @ts-expect-error TODO configure TypeScript project references
40+
// @ts-expect-error: TODO configure TypeScript project references
4141
h1(properties) {
42-
// @ts-expect-error TODO configure TypeScript project references
42+
// @ts-expect-error: TODO configure TypeScript project references
4343
return <h1 style={{color: 'tomato'}} {...properties} />
4444
}
4545
}}
@@ -68,7 +68,7 @@ test('@mdx-js/preact', async function (t) {
6868
* @returns
6969
* Element.
7070
*/
71-
// @ts-expect-error TODO configure TypeScript project references
71+
// @ts-expect-error: TODO configure TypeScript project references
7272
wrapper(properties) {
7373
return <div id="layout" {...properties} />
7474
}
@@ -93,23 +93,23 @@ test('@mdx-js/preact', async function (t) {
9393
render(
9494
<MDXProvider
9595
components={{
96-
// @ts-expect-error TODO configure TypeScript project references
96+
// @ts-expect-error: TODO configure TypeScript project references
9797
h1(properties) {
98-
// @ts-expect-error TODO configure TypeScript project references
98+
// @ts-expect-error: TODO configure TypeScript project references
9999
return <h1 style={{color: 'tomato'}} {...properties} />
100100
},
101-
// @ts-expect-error TODO configure TypeScript project references
101+
// @ts-expect-error: TODO configure TypeScript project references
102102
h2(properties) {
103-
// @ts-expect-error TODO configure TypeScript project references
103+
// @ts-expect-error: TODO configure TypeScript project references
104104
return <h2 style={{color: 'rebeccapurple'}} {...properties} />
105105
}
106106
}}
107107
>
108108
<MDXProvider
109109
components={{
110-
// @ts-expect-error TODO configure TypeScript project references
110+
// @ts-expect-error: TODO configure TypeScript project references
111111
h2(properties) {
112-
// @ts-expect-error TODO configure TypeScript project references
112+
// @ts-expect-error: TODO configure TypeScript project references
113113
return <h2 style={{color: 'papayawhip'}} {...properties} />
114114
}
115115
}}
@@ -133,24 +133,24 @@ test('@mdx-js/preact', async function (t) {
133133
render(
134134
<MDXProvider
135135
components={{
136-
// @ts-expect-error TODO configure TypeScript project references
136+
// @ts-expect-error: TODO configure TypeScript project references
137137
h1(properties) {
138-
// @ts-expect-error TODO configure TypeScript project references
138+
// @ts-expect-error: TODO configure TypeScript project references
139139
return <h1 style={{color: 'tomato'}} {...properties} />
140140
},
141-
// @ts-expect-error TODO configure TypeScript project references
141+
// @ts-expect-error: TODO configure TypeScript project references
142142
h2(properties) {
143-
// @ts-expect-error TODO configure TypeScript project references
143+
// @ts-expect-error: TODO configure TypeScript project references
144144
return <h2 style={{color: 'rebeccapurple'}} {...properties} />
145145
}
146146
}}
147147
>
148148
<MDXProvider
149-
// @ts-expect-error TODO configure TypeScript project references
149+
// @ts-expect-error: TODO configure TypeScript project references
150150
components={function () {
151151
return {
152152
h2(properties) {
153-
// @ts-expect-error TODO configure TypeScript project references
153+
// @ts-expect-error: TODO configure TypeScript project references
154154
return <h2 style={{color: 'papayawhip'}} {...properties} />
155155
}
156156
}
@@ -176,9 +176,9 @@ test('@mdx-js/preact', async function (t) {
176176
render(
177177
<MDXProvider
178178
components={{
179-
// @ts-expect-error TODO configure TypeScript project references
179+
// @ts-expect-error: TODO configure TypeScript project references
180180
h1(properties) {
181-
// @ts-expect-error TODO configure TypeScript project references
181+
// @ts-expect-error: TODO configure TypeScript project references
182182
return <h1 style={{color: 'tomato'}} {...properties} />
183183
}
184184
}}
@@ -205,20 +205,20 @@ test('@mdx-js/preact', async function (t) {
205205
render(
206206
<MDXProvider
207207
components={{
208-
// @ts-expect-error TODO configure TypeScript project references
208+
// @ts-expect-error: TODO configure TypeScript project references
209209
h1(properties) {
210-
// @ts-expect-error TODO configure TypeScript project references
210+
// @ts-expect-error: TODO configure TypeScript project references
211211
return <h1 style={{color: 'tomato'}} {...properties} />
212212
}
213213
}}
214214
>
215215
<MDXProvider
216216
disableParentContext
217-
// @ts-expect-error TODO configure TypeScript project references
217+
// @ts-expect-error: TODO configure TypeScript project references
218218
components={function () {
219219
return {
220220
h2(properties) {
221-
// @ts-expect-error TODO configure TypeScript project references
221+
// @ts-expect-error: TODO configure TypeScript project references
222222
return <h2 style={{color: 'papayawhip'}} {...properties} />
223223
}
224224
}

packages/remark-mdx/lib/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ const emptyOptions = {}
1919
* Add support for MDX (JSX: `<Video id={123} />`, export/imports: `export {x}
2020
* from 'y'`; and expressions: `{1 + 1}`).
2121
*
22+
* @this {Processor}
23+
* Processor.
2224
* @param {Readonly<Options> | null | undefined} [options]
2325
* Configuration (optional).
2426
* @returns {undefined}
2527
* Nothing.
2628
*/
2729
export default function remarkMdx(options) {
28-
// @ts-expect-error: TS is wrong about `this`.
29-
// eslint-disable-next-line unicorn/no-this-assignment
30-
const self = /** @type {Processor} */ (this)
30+
const self = this
3131
const settings = options || emptyOptions
3232
const data = self.data()
3333

packages/remark-mdx/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
"prettier": true,
5555
"rules": {
5656
"logical-assignment-operators": "off",
57-
"n/file-extension-in-import": "off"
57+
"n/file-extension-in-import": "off",
58+
"unicorn/no-this-assignment": "off"
5859
}
5960
}
6061
}

website/types.d.ts

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
11
import type {Author} from './generate.js'
22

3+
// Register data on `estree`.
4+
declare module 'estree' {
5+
interface BaseNode {
6+
/**
7+
* Field patched by `acorn`.
8+
*
9+
* Registered by types for the MDX website for the playground.
10+
*/
11+
end?: number | undefined
12+
13+
/**
14+
* Field patched by `acorn`.
15+
*
16+
* Registered by types for the MDX website for the playground.
17+
*/
18+
start?: number | undefined
19+
}
20+
}
21+
22+
// Register data on hast.
23+
declare module 'hast' {
24+
interface ElementData {
25+
/**
26+
* `meta` field available on `<code>` elements; added by `mdast-util-to-hast`.
27+
*
28+
* Registered by `website/types.d.ts` for the MDX website.
29+
*/
30+
meta?: string | null | undefined
31+
}
32+
}
33+
334
// Add custom data supported when `rehype-document` is added.
435
declare module 'vfile' {
536
interface DataMapMeta {
@@ -22,15 +53,3 @@ declare module 'vfile' {
2253
meta: DataMapMeta
2354
}
2455
}
25-
26-
// Register data on hast.
27-
declare module 'hast' {
28-
interface ElementData {
29-
/**
30-
* `meta` field available on `<code>` elements; added by `mdast-util-to-hast`.
31-
*
32-
* Registered by `website/types.d.ts` for the MDX website.
33-
*/
34-
meta?: string | null | undefined
35-
}
36-
}

0 commit comments

Comments
 (0)