Skip to content

Commit

Permalink
fix: remove unknown from walkTokens return types
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed Aug 26, 2023
1 parent 5bc2fdb commit dbbefea
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/Instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type { MarkedExtension, MarkedOptions } from './MarkedOptions.ts';
import type { Token, Tokens, TokensList } from './Tokens.ts';

export type ResultCallback = (error: Error | null, parseResult?: string) => undefined | void;
export type MaybePromise = void | Promise<void>;

type UnknownFunction = (...args: unknown[]) => unknown;
type GenericRendererFunction = (...args: unknown[]) => string | false;
Expand Down Expand Up @@ -42,8 +43,8 @@ export class Marked {
/**
* Run callback for every token
*/
walkTokens <T = void>(tokens: Token[] | TokensList, callback: (token: Token) => T | T[]) {
let values: T[] = [];
walkTokens(tokens: Token[] | TokensList, callback: (token: Token) => MaybePromise | MaybePromise[]) {
let values: MaybePromise[] = [];
for (const token of tokens) {
values = values.concat(callback.call(this, token));
switch (token.type) {
Expand Down Expand Up @@ -215,7 +216,7 @@ export class Marked {
const walkTokens = this.defaults.walkTokens;
const packWalktokens = pack.walkTokens;
opts.walkTokens = function(token) {
let values: Array<Promise<void> | void | unknown> = [];
let values: MaybePromise[] = [];
values.push(packWalktokens.call(this, token));
if (walkTokens) {
values = values.concat(walkTokens.call(this, token));
Expand Down
4 changes: 2 additions & 2 deletions src/MarkedOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export interface MarkedExtension {
* Each token is passed by reference so updates are persisted when passed to the parser.
* The return value of the function is ignored.
*/
walkTokens?: ((token: Token) => void | unknown | Promise<void>) | undefined | null;
walkTokens?: ((token: Token) => void | Promise<void>) | undefined | null;
/**
* Generate closing slash for self-closing tags (<br/> instead of <br>)
* @deprecated Deprecated in v5.0.0 use marked-xhtml to emit self-closing HTML tags for void elements (<br/>, <img/>, etc.) with a "/" as required by XHTML.
Expand Down Expand Up @@ -213,5 +213,5 @@ export interface MarkedOptions extends Omit<MarkedExtension, 'renderer' | 'token
/**
* walkTokens function returns array of values for Promise.all
*/
walkTokens?: null | ((token: Token) => void | (unknown | Promise<void>)[]);
walkTokens?: null | ((token: Token) => void | Promise<void> | (void | Promise<void>)[]);
}
4 changes: 2 additions & 2 deletions src/marked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from './defaults.ts';
import type { MarkedExtension, MarkedOptions } from './MarkedOptions.ts';
import type { Token, TokensList } from './Tokens.ts';
import type { ResultCallback } from './Instance.ts';
import type { ResultCallback, MaybePromise } from './Instance.ts';

const markedInstance = new Marked();

Expand Down Expand Up @@ -94,7 +94,7 @@ marked.use = function(...args: MarkedExtension[]) {
* Run callback for every token
*/

marked.walkTokens = function <T = void>(tokens: Token[] | TokensList, callback: (token: Token) => T | T[]) {
marked.walkTokens = function(tokens: Token[] | TokensList, callback: (token: Token) => MaybePromise | MaybePromise[]) {
return markedInstance.walkTokens(tokens, callback);
};

Expand Down

0 comments on commit dbbefea

Please sign in to comment.