fix: fix marked types (#3103)
This commit is contained in:
parent
4f3304018e
commit
edae309505
@ -26,13 +26,13 @@ const markedInstance = new Marked();
|
|||||||
export function marked(src: string, options: MarkedOptions & { async: true }): Promise<string>;
|
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 src String of markdown source to be compiled
|
||||||
* @param options Optional hash of options
|
* @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> {
|
export function marked(src: string, opt?: MarkedOptions): string | Promise<string> {
|
||||||
return markedInstance.parse(src, opt);
|
return markedInstance.parse(src, opt);
|
||||||
}
|
}
|
||||||
|
@ -247,13 +247,21 @@ marked.use(asyncExtension);
|
|||||||
const md = '# foobar';
|
const md = '# foobar';
|
||||||
const asyncMarked: string = await marked(md, { async: true });
|
const asyncMarked: string = await marked(md, { async: true });
|
||||||
const promiseMarked: Promise<string> = 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 });
|
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);
|
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 asyncMarkedParse: string = await marked.parse(md, { async: true });
|
||||||
const promiseMarkedParse: Promise<string> = 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 });
|
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);
|
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
|
// Tests for List and ListItem
|
||||||
|
Loading…
x
Reference in New Issue
Block a user