-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.test-d.ts
25 lines (22 loc) · 1.06 KB
/
index.test-d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { expectType, expectAssignable } from "tsd";
import KeyvCache, { type CacheHandlers } from "./index";
const cache = KeyvCache<any>();
expectAssignable<CacheHandlers<any>>(cache);
if (cache) {
// check the method signatures
expectAssignable<CacheHandlers<any>["get"]>(cache.get);
expectAssignable<CacheHandlers<any>["set"]>(cache.set);
expectAssignable<CacheHandlers<any>["has"]>(cache.has);
expectAssignable<CacheHandlers<any>["remove"]>(cache.remove);
expectAssignable<CacheHandlers<any>["removePattern"]>(cache.removePattern);
expectAssignable<CacheHandlers<any>["keys"]>(cache.keys);
expectAssignable<CacheHandlers<any>["clear"]>(cache.clear);
// check the methods return type signatures
expectType<Promise<any>>(cache.get("key"));
expectType<Promise<string>>(cache.set("key", "value", 1000));
expectType<Promise<boolean>>(cache.has("key"));
expectType<Promise<boolean>>(cache.remove("key"));
expectType<Promise<boolean[]>>(cache.removePattern("key"));
expectType<Promise<string[]>>(cache.keys());
expectType<Promise<boolean>>(cache.clear());
}