diff --git a/types/got/got-tests.ts b/types/got/got-tests.ts index 7c089cc91b..1626cae86a 100644 --- a/types/got/got-tests.ts +++ b/types/got/got-tests.ts @@ -253,7 +253,7 @@ got('todomvc', { }).then(res => res.fromCache); got('todomvc', { - cache: new QuickLRU(), + cache: new QuickLRU({maxSize: 10}), }).then(res => res.fromCache); got(new url.URL('http://todomvc.com')); diff --git a/types/got/v8/got-tests.ts b/types/got/v8/got-tests.ts index 610ac87c26..5e115e96ac 100644 --- a/types/got/v8/got-tests.ts +++ b/types/got/v8/got-tests.ts @@ -252,7 +252,7 @@ got('todomvc', { }).then(res => res.fromCache); got('todomvc', { - cache: new QuickLRU(), + cache: new QuickLRU({maxSize: 10}), }).then(res => res.fromCache); got(new url.URL('http://todomvc.com')); diff --git a/types/quick-lru/index.d.ts b/types/quick-lru/index.d.ts index 7ce12e397c..65e15c60a4 100644 --- a/types/quick-lru/index.d.ts +++ b/types/quick-lru/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for quick-lru 1.1 +// Type definitions for quick-lru 2.0 // Project: https://github.com/sindresorhus/quick-lru#readme // Definitions by: BendingBender // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -7,13 +7,13 @@ export = QuickLRU; declare class QuickLRU implements Iterable<[K, V]> { readonly size: number; - constructor(options?: QuickLRU.Options); + constructor(options: QuickLRU.Options); [Symbol.iterator](): Iterator<[K, V]>; set(key: K, value: V): this; get(key: K): V | undefined; has(key: K): boolean; peek(key: K): V | undefined; - delete(key: K): void; + delete(key: K): boolean; clear(): void; keys(): Iterable; values(): Iterable; diff --git a/types/quick-lru/quick-lru-tests.ts b/types/quick-lru/quick-lru-tests.ts index 140e25bcd8..5a3c5fb8f8 100644 --- a/types/quick-lru/quick-lru-tests.ts +++ b/types/quick-lru/quick-lru-tests.ts @@ -1,29 +1,25 @@ import QuickLRU = require('quick-lru'); -let num: number; -let numu: number | undefined; -let str: string; -let bool: boolean; +const lru = new QuickLRU({ maxSize: 1000 }); +new QuickLRU(); // $ExpectError -const lru = new QuickLRU({maxSize: 1000}); - -lru.set('🦄', 1).set('🌈', 2); -numu = lru.get('🦄'); -bool = lru.has('🦄'); -numu = lru.peek('🦄'); -lru.delete('🦄'); -lru.clear(); -num = lru.size; +lru.set('🦄', 1).set('🌈', 2); // $ExpectType QuickLRU +lru.get('🦄'); // $ExpectType number | undefined +lru.has('🦄'); // $ExpectType boolean +lru.peek('🦄'); // $ExpectType number | undefined +lru.delete('🦄'); // $ExpectType boolean +lru.clear(); // $ExpectType void +lru.size; // $ExpectType number for (const [key, value] of lru) { - str = key; - num = value; + key; // $ExpectType string + value; // $ExpectType number } for (const key of lru.keys()) { - str = key; + key; // $ExpectType string } for (const value of lru.values()) { - num = value; + value; // $ExpectType number } diff --git a/types/quick-lru/tsconfig.json b/types/quick-lru/tsconfig.json index c75dcdb96b..788f560163 100644 --- a/types/quick-lru/tsconfig.json +++ b/types/quick-lru/tsconfig.json @@ -21,4 +21,4 @@ "index.d.ts", "quick-lru-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/quick-lru/v1/index.d.ts b/types/quick-lru/v1/index.d.ts new file mode 100644 index 0000000000..7ce12e397c --- /dev/null +++ b/types/quick-lru/v1/index.d.ts @@ -0,0 +1,26 @@ +// Type definitions for quick-lru 1.1 +// Project: https://github.com/sindresorhus/quick-lru#readme +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export = QuickLRU; + +declare class QuickLRU implements Iterable<[K, V]> { + readonly size: number; + constructor(options?: QuickLRU.Options); + [Symbol.iterator](): Iterator<[K, V]>; + set(key: K, value: V): this; + get(key: K): V | undefined; + has(key: K): boolean; + peek(key: K): V | undefined; + delete(key: K): void; + clear(): void; + keys(): Iterable; + values(): Iterable; +} + +declare namespace QuickLRU { + interface Options { + maxSize: number; + } +} diff --git a/types/quick-lru/v1/quick-lru-tests.ts b/types/quick-lru/v1/quick-lru-tests.ts new file mode 100644 index 0000000000..140e25bcd8 --- /dev/null +++ b/types/quick-lru/v1/quick-lru-tests.ts @@ -0,0 +1,29 @@ +import QuickLRU = require('quick-lru'); + +let num: number; +let numu: number | undefined; +let str: string; +let bool: boolean; + +const lru = new QuickLRU({maxSize: 1000}); + +lru.set('🦄', 1).set('🌈', 2); +numu = lru.get('🦄'); +bool = lru.has('🦄'); +numu = lru.peek('🦄'); +lru.delete('🦄'); +lru.clear(); +num = lru.size; + +for (const [key, value] of lru) { + str = key; + num = value; +} + +for (const key of lru.keys()) { + str = key; +} + +for (const value of lru.values()) { + num = value; +} diff --git a/types/quick-lru/v1/tsconfig.json b/types/quick-lru/v1/tsconfig.json new file mode 100644 index 0000000000..ae4a2956c7 --- /dev/null +++ b/types/quick-lru/v1/tsconfig.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es2015", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../../", + "typeRoots": [ + "../../" + ], + "paths": { + "quick-lru": [ + "quick-lru/v1" + ] + }, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "quick-lru-tests.ts" + ] +} diff --git a/types/quick-lru/v1/tslint.json b/types/quick-lru/v1/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/quick-lru/v1/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }