diff --git a/src/marked.ts b/src/marked.ts index 74a596d943..9301db095c 100644 --- a/src/marked.ts +++ b/src/marked.ts @@ -26,13 +26,13 @@ const markedInstance = new Marked(); export function marked(src: string, options: MarkedOptions & { async: true }): Promise; /** - * Compiles markdown to HTML synchronously. + * Compiles markdown to HTML. * * @param src String of markdown source to be compiled * @param options Optional hash of options - * @return String of compiled HTML + * @return String of compiled HTML. Wil be a Promise of string if async is set to true by any extensions. */ -export function marked(src: string, options?: MarkedOptions): string; +export function marked(src: string, options?: MarkedOptions): string | Promise; export function marked(src: string, opt?: MarkedOptions): string | Promise { return markedInstance.parse(src, opt); } diff --git a/test/types/marked.ts b/test/types/marked.ts index 53f991fda6..dcf9da5e3f 100644 --- a/test/types/marked.ts +++ b/test/types/marked.ts @@ -247,13 +247,21 @@ marked.use(asyncExtension); const md = '# foobar'; const asyncMarked: string = await marked(md, { async: true }); const promiseMarked: Promise = marked(md, { async: true }); +// @ts-expect-error marked can still be async if an extension sets `async: true` const notAsyncMarked: string = marked(md, { async: false }); +// @ts-expect-error marked can still be async if an extension sets `async: true` const defaultMarked: string = marked(md); +// as string can be used if no extensions set `async: true` +const stringMarked: string = marked(md) as string; const asyncMarkedParse: string = await marked.parse(md, { async: true }); const promiseMarkedParse: Promise = marked.parse(md, { async: true }); +// @ts-expect-error marked can still be async if an extension sets `async: true` const notAsyncMarkedParse: string = marked.parse(md, { async: false }); +// @ts-expect-error marked can still be async if an extension sets `async: true` const defaultMarkedParse: string = marked.parse(md); +// as string can be used if no extensions set `async: true` +const stringMarkedParse: string = marked.parse(md) as string; })(); // Tests for List and ListItem