Skip to content

Commit

Permalink
fix: inaccurate types (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang authored Dec 31, 2022
1 parent 83c85a0 commit f53c77d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export = class Cache<T> {
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();
Expand Down
2 changes: 1 addition & 1 deletion lib/html_tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!');

Expand Down
9 changes: 7 additions & 2 deletions lib/permalink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/relative_url.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import encodeURL from './encode_url';
import Cache from './cache';
const cache = new Cache();
const cache = new Cache<string>();

function relativeUrlHelper(from = '', to = '') {
return cache.apply(`${from}-${to}`, () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/url_for.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>();

function urlForHelper(path = '/', options) {
if (/^(#|\/\/|http(s)?:)/.test(path)) return path;
Expand Down

0 comments on commit f53c77d

Please sign in to comment.