Skip to content

Commit eefd5f1

Browse files
committed
Fix types for bridge mode with missing overload
Related-to: remarkjs/remark-retext#19.
1 parent c76ab4b commit eefd5f1

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

lib/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ import {toHast} from 'mdast-util-to-hast'
132132
* @param {Readonly<Options> | null | undefined} [options]
133133
* @returns {TransformMutate}
134134
*
135+
* @overload
136+
* @param {Readonly<Options> | Processor | null | undefined} [destination]
137+
* @param {Readonly<Options> | null | undefined} [options]
138+
* @returns {TransformBridge | TransformMutate}
139+
*
135140
* @param {Readonly<Options> | Processor | null | undefined} [destination]
136141
* Processor or configuration (optional).
137142
* @param {Readonly<Options> | null | undefined} [options]

test.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ test('remarkRehype', async function (t) {
6868
await t.test(
6969
'should mutate with `processor: undefined` and options',
7070
async function () {
71+
// This tests the file set passed by `unified-engine`.
7172
assert.equal(
7273
String(
7374
await unified()
7475
.use(remarkParse)
75-
// @ts-expect-error: this tests the file set passed by `unified-engine`.
7676
.use(remarkRehype, undefined, {handlers: {text}})
7777
.use(rehypeStringify)
7878
.process('# hi')
@@ -87,7 +87,6 @@ test('remarkRehype', async function (t) {
8787
String(
8888
await unified()
8989
.use(remarkParse)
90-
// @ts-expect-error: TS currently barfs on overloads that result in mutate/bridges.
9190
.use(remarkRehype, unified())
9291
.use(remarkStringify)
9392
.process('## Hello, world! ##')
@@ -101,7 +100,6 @@ test('remarkRehype', async function (t) {
101100
String(
102101
await unified()
103102
.use(remarkParse)
104-
// @ts-expect-error: TS currently barfs on overloads that result in mutate/bridges.
105103
.use(remarkRehype, unified(), {allowDangerousHtml: true})
106104
.use(remarkStringify)
107105
.process('## Hello, <i>world</i>! ##')
@@ -111,19 +109,18 @@ test('remarkRehype', async function (t) {
111109
})
112110

113111
await t.test('should understand bridge types', async function () {
114-
const treeIn = unified().use(remarkParse).parse('hi')
115-
// @ts-expect-error: TS currently barfs on overloads that result in mutate/bridges.
112+
const treeIn = unified().use(remarkParse).parse('# hi')
116113
const treeOut = await unified().use(remarkRehype, unified()).run(treeIn)
117114
// @ts-expect-error: TS currently barfs on overloads that result in mutate/bridges.
118115
const document = unified().use(remarkStringify).stringify(treeOut)
119-
assert.equal(document, 'hi\n')
116+
assert.equal(document, '# hi\n')
120117
})
121118

122119
await t.test('should understand mutate types', async function () {
123-
const treeIn = unified().use(remarkParse).parse('hi')
120+
const treeIn = unified().use(remarkParse).parse('# hi')
124121
const treeOut = await unified().use(remarkRehype).run(treeIn)
125122
const document = unified().use(rehypeStringify).stringify(treeOut)
126-
assert.equal(document, '<p>hi</p>')
123+
assert.equal(document, '<h1>hi</h1>')
127124
})
128125
})
129126

0 commit comments

Comments
 (0)