fix: fix marked types (#3103)

This commit is contained in:
Tony Brix 2023-11-28 20:51:36 -07:00 committed by GitHub
parent 4f3304018e
commit edae309505
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View File

@ -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);
}

View File

@ -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