I'm trying to write a local filesystem cache:
const fetchDocument = pMemoize(async (url: string): Promise<string> => {
const request = await fetch(url, {
headers: {
Accept: 'text/html',
},
});
return request.text();
}, {
cache: {
async get(url: string): Promise<string | undefined> {
try {
return await readFile(`./test/.cache/${filenamify(url)}.html`, 'utf8');
} catch {
return undefined;
}
},
async set(url: string, contents: string): Promise<void> {
await writeFile(`./test/.cache/${filenamify(url)}.html`, contents);
},
async has(url: string): Promise<boolean> {
return Boolean(await this.get(url));
}
}
});
Every cache method is failing with:
Type '(url: string) => Promise<string | undefined>' is not assignable to type '(key: unknown) => string | Promise<string | undefined> | undefined'.
Types of parameters 'url' and 'key' are incompatible.
Type 'unknown' is not assignable to type 'string'.ts(2322)
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too