Skip to content

Commit edae309

Browse files
authored
fix: fix marked types (#3103)
1 parent 4f33040 commit edae309

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/marked.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ const markedInstance = new Marked();
2626
export function marked(src: string, options: MarkedOptions & { async: true }): Promise<string>;
2727

2828
/**
29-
* Compiles markdown to HTML synchronously.
29+
* Compiles markdown to HTML.
3030
*
3131
* @param src String of markdown source to be compiled
3232
* @param options Optional hash of options
33-
* @return String of compiled HTML
33+
* @return String of compiled HTML. Wil be a Promise of string if async is set to true by any extensions.
3434
*/
35-
export function marked(src: string, options?: MarkedOptions): string;
35+
export function marked(src: string, options?: MarkedOptions): string | Promise<string>;
3636
export function marked(src: string, opt?: MarkedOptions): string | Promise<string> {
3737
return markedInstance.parse(src, opt);
3838
}

test/types/marked.ts

+8
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,21 @@ marked.use(asyncExtension);
247247
const md = '# foobar';
248248
const asyncMarked: string = await marked(md, { async: true });
249249
const promiseMarked: Promise<string> = marked(md, { async: true });
250+
// @ts-expect-error marked can still be async if an extension sets `async: true`
250251
const notAsyncMarked: string = marked(md, { async: false });
252+
// @ts-expect-error marked can still be async if an extension sets `async: true`
251253
const defaultMarked: string = marked(md);
254+
// as string can be used if no extensions set `async: true`
255+
const stringMarked: string = marked(md) as string;
252256

253257
const asyncMarkedParse: string = await marked.parse(md, { async: true });
254258
const promiseMarkedParse: Promise<string> = marked.parse(md, { async: true });
259+
// @ts-expect-error marked can still be async if an extension sets `async: true`
255260
const notAsyncMarkedParse: string = marked.parse(md, { async: false });
261+
// @ts-expect-error marked can still be async if an extension sets `async: true`
256262
const defaultMarkedParse: string = marked.parse(md);
263+
// as string can be used if no extensions set `async: true`
264+
const stringMarkedParse: string = marked.parse(md) as string;
257265
})();
258266

259267
// Tests for List and ListItem

0 commit comments

Comments
 (0)