diff --git a/lib/cache.ts b/lib/cache.ts index 605bae68..4b0de14a 100644 --- a/lib/cache.ts +++ b/lib/cache.ts @@ -21,7 +21,7 @@ export = class Cache { this.cache.delete(id); } - apply(id: string, value) { + apply(id: string, value): T { if (this.has(id)) return this.get(id); if (typeof value === 'function') value = value(); diff --git a/lib/html_tag.ts b/lib/html_tag.ts index c5efc318..4d357a70 100644 --- a/lib/html_tag.ts +++ b/lib/html_tag.ts @@ -15,7 +15,7 @@ function encSrcset(str: string) { } function htmlTag(tag: string, attrs: { - [key: string]: string | boolean; + [key: string]: string | boolean | null | undefined; }, text?: string, escape = true) { if (!tag) throw new TypeError('tag is required!'); diff --git a/lib/permalink.ts b/lib/permalink.ts index 6b999b57..53fdac89 100644 --- a/lib/permalink.ts +++ b/lib/permalink.ts @@ -2,14 +2,19 @@ import escapeRegExp from './escape_regexp'; const rParam = /:(\w*[^_\W])/g; +interface Options { + segments?: { + [key: string]: RegExp | string; + } +} + class Permalink { rule: string; regex: RegExp; params: string[]; - constructor(rule: string, options: { segments?: any; }) { + constructor(rule: string, options: Options = {}) { if (!rule) { throw new TypeError('rule is required!'); } - options = options || {}; const segments = options.segments || {}; const params = []; const regex = escapeRegExp(rule) diff --git a/lib/relative_url.ts b/lib/relative_url.ts index 8c2080a2..a90fab00 100644 --- a/lib/relative_url.ts +++ b/lib/relative_url.ts @@ -1,6 +1,6 @@ import encodeURL from './encode_url'; import Cache from './cache'; -const cache = new Cache(); +const cache = new Cache(); function relativeUrlHelper(from = '', to = '') { return cache.apply(`${from}-${to}`, () => { diff --git a/lib/url_for.ts b/lib/url_for.ts index 482b8e53..7ab50408 100644 --- a/lib/url_for.ts +++ b/lib/url_for.ts @@ -3,7 +3,7 @@ import encodeURL from './encode_url'; import relative_url from './relative_url'; import prettyUrls from './pretty_urls'; import Cache from './cache'; -const cache = new Cache(); +const cache = new Cache(); function urlForHelper(path = '/', options) { if (/^(#|\/\/|http(s)?:)/.test(path)) return path;