diff --git a/mem/index.d.ts b/mem/index.d.ts new file mode 100644 index 0000000000..3ba85ce926 --- /dev/null +++ b/mem/index.d.ts @@ -0,0 +1,18 @@ +// Type definitions for mem 1.1.0 +// Project: https://github.com/sindresorhus/mem +// Definitions by: Sam Verschueren +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +interface Options { + maxAge?: number; + cacheKey?: (...args: any[]) => string; + cache?: any; +} + +declare const mem: { + any>(fn: F, options?: Options): F; + clear any>(fn: F): void; +}; + +declare namespace mem { } +export = mem; diff --git a/mem/mem-tests.ts b/mem/mem-tests.ts new file mode 100644 index 0000000000..efa6214fca --- /dev/null +++ b/mem/mem-tests.ts @@ -0,0 +1,10 @@ +import * as mem from 'mem'; + +let i = 0; +const memoized = mem((arg: string) => ++i); +const ret1: number = memoized('foo'); + +// Clear the memoized data +mem.clear(memoized); + +const ret2: Promise = mem(() => Promise.resolve('foo'))(); diff --git a/mem/tsconfig.json b/mem/tsconfig.json new file mode 100644 index 0000000000..65d9a6999c --- /dev/null +++ b/mem/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "mem-tests.ts" + ] +} \ No newline at end of file diff --git a/mem/tslint.json b/mem/tslint.json new file mode 100644 index 0000000000..2221e40e4a --- /dev/null +++ b/mem/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } \ No newline at end of file