Add type definitions for flat-cache (#35472)

This commit is contained in:
Kevin Pollet 2019-05-15 20:01:38 +04:00 committed by Nathan Shively-Sanders
parent dbe44d6d01
commit 5f983eff84
4 changed files with 90 additions and 0 deletions

View File

@ -0,0 +1,39 @@
import * as flatCache from "flat-cache";
flatCache.load(""); // $ExpectType Cache
flatCache.load("", ""); // $ExpectType Cache
flatCache.create(""); // $ExpectType Cache
flatCache.create("", ""); // $ExpectType Cache
flatCache.createFromFile(""); // $ExpectType Cache
flatCache.clearCacheById(""); // $ExpectType boolean
flatCache.clearCacheById("", ""); // $ExpectType boolean
flatCache.clearAll(); // $ExpectType boolean
flatCache.clearAll(""); // $ExpectType boolean
const cache = flatCache.load(""); // $ExpectType Cache
cache.load(""); // $ExpectType void
cache.load("", ""); // $ExpectType void
cache.loadFile(""); // $ExpectType void
cache.all(); // $ExpectType { [key: string]: any; }
cache.keys(); // $ExpectType string[]
cache.setKey("", ""); // $ExpectType void
cache.removeKey(""); // $ExpectType void
cache.getKey(""); // $ExpectType any
cache.save(); // $ExpectType void
cache.save(true); // $ExpectType void
cache.removeCacheFile(); // $ExpectType boolean
cache.destroy(); // $ExpectType void

27
types/flat-cache/index.d.ts vendored Normal file
View File

@ -0,0 +1,27 @@
// Type definitions for flat-cache 2.0
// Project: https://github.com/royriojas/flat-cache#readme
// Definitions by: Kevin Pollet <https://github.com/kevinpollet>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export interface Cache {
load(cacheId: string, cacheDir?: string): void;
loadFile(pathToFile: string): void;
all(): { [key: string]: any };
keys(): string[];
setKey(key: string, value: any): void;
removeKey(key: string): void;
getKey(key: string): any;
save(noPrune?: boolean): void;
removeCacheFile(): boolean;
destroy(): void;
}
export function load(cacheId: string, cacheDir?: string): Cache;
export function create(cacheId: string, cacheDir?: string): Cache;
export function createFromFile(filePath: string): Cache;
export function clearCacheById(cacheId: string, cacheDir?: string): boolean;
export function clearAll(cacheDir?: string): boolean;

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"flat-cache-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }