Skip to content

Commit

Permalink
fix: fix marked types (#3103)
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed Nov 29, 2023
1 parent 4f33040 commit edae309
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/marked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ const markedInstance = new Marked();
export function marked(src: string, options: MarkedOptions & { async: true }): Promise<string>;

/**
* 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<string>;
export function marked(src: string, opt?: MarkedOptions): string | Promise<string> {
return markedInstance.parse(src, opt);
}
Expand Down
8 changes: 8 additions & 0 deletions test/types/marked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,21 @@ marked.use(asyncExtension);
const md = '# foobar';
const asyncMarked: string = await marked(md, { async: true });
const promiseMarked: Promise<string> = 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<string> = 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
Expand Down

1 comment on commit edae309

@vercel
Copy link

@vercel vercel bot commented on edae309 Nov 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.