From a6d7daa8d9fdc033dedcc5d0530839e02ae21c91 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Sun, 23 Dec 2018 14:02:29 +0100 Subject: [PATCH 1/3] move previous major types to sub-dir --- types/quick-lru/{ => v1}/index.d.ts | 0 types/quick-lru/{ => v1}/quick-lru-tests.ts | 0 types/quick-lru/{ => v1}/tsconfig.json | 11 ++++++++--- types/quick-lru/{ => v1}/tslint.json | 0 4 files changed, 8 insertions(+), 3 deletions(-) rename types/quick-lru/{ => v1}/index.d.ts (100%) rename types/quick-lru/{ => v1}/quick-lru-tests.ts (100%) rename types/quick-lru/{ => v1}/tsconfig.json (75%) rename types/quick-lru/{ => v1}/tslint.json (100%) diff --git a/types/quick-lru/index.d.ts b/types/quick-lru/v1/index.d.ts similarity index 100% rename from types/quick-lru/index.d.ts rename to types/quick-lru/v1/index.d.ts diff --git a/types/quick-lru/quick-lru-tests.ts b/types/quick-lru/v1/quick-lru-tests.ts similarity index 100% rename from types/quick-lru/quick-lru-tests.ts rename to types/quick-lru/v1/quick-lru-tests.ts diff --git a/types/quick-lru/tsconfig.json b/types/quick-lru/v1/tsconfig.json similarity index 75% rename from types/quick-lru/tsconfig.json rename to types/quick-lru/v1/tsconfig.json index c75dcdb96b..ae4a2956c7 100644 --- a/types/quick-lru/tsconfig.json +++ b/types/quick-lru/v1/tsconfig.json @@ -9,10 +9,15 @@ "noImplicitThis": true, "strictNullChecks": true, "strictFunctionTypes": true, - "baseUrl": "../", + "baseUrl": "../../", "typeRoots": [ - "../" + "../../" ], + "paths": { + "quick-lru": [ + "quick-lru/v1" + ] + }, "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true @@ -21,4 +26,4 @@ "index.d.ts", "quick-lru-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/quick-lru/tslint.json b/types/quick-lru/v1/tslint.json similarity index 100% rename from types/quick-lru/tslint.json rename to types/quick-lru/v1/tslint.json From d2d7c2cb2747a012e1a0e869a86768405e32d9af Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Sun, 23 Dec 2018 14:23:24 +0100 Subject: [PATCH 2/3] [quick-lru] Add types for v2 --- types/quick-lru/index.d.ts | 26 ++++++++++++++++++++++++++ types/quick-lru/quick-lru-tests.ts | 25 +++++++++++++++++++++++++ types/quick-lru/tsconfig.json | 24 ++++++++++++++++++++++++ types/quick-lru/tslint.json | 1 + 4 files changed, 76 insertions(+) create mode 100644 types/quick-lru/index.d.ts create mode 100644 types/quick-lru/quick-lru-tests.ts create mode 100644 types/quick-lru/tsconfig.json create mode 100644 types/quick-lru/tslint.json diff --git a/types/quick-lru/index.d.ts b/types/quick-lru/index.d.ts new file mode 100644 index 0000000000..65e15c60a4 --- /dev/null +++ b/types/quick-lru/index.d.ts @@ -0,0 +1,26 @@ +// Type definitions for quick-lru 2.0 +// 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): boolean; + clear(): void; + keys(): Iterable; + values(): Iterable; +} + +declare namespace QuickLRU { + interface Options { + maxSize: number; + } +} diff --git a/types/quick-lru/quick-lru-tests.ts b/types/quick-lru/quick-lru-tests.ts new file mode 100644 index 0000000000..5a3c5fb8f8 --- /dev/null +++ b/types/quick-lru/quick-lru-tests.ts @@ -0,0 +1,25 @@ +import QuickLRU = require('quick-lru'); + +const lru = new QuickLRU({ maxSize: 1000 }); +new QuickLRU(); // $ExpectError + +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) { + key; // $ExpectType string + value; // $ExpectType number +} + +for (const key of lru.keys()) { + key; // $ExpectType string +} + +for (const value of lru.values()) { + value; // $ExpectType number +} diff --git a/types/quick-lru/tsconfig.json b/types/quick-lru/tsconfig.json new file mode 100644 index 0000000000..788f560163 --- /dev/null +++ b/types/quick-lru/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es2015", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "quick-lru-tests.ts" + ] +} diff --git a/types/quick-lru/tslint.json b/types/quick-lru/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/quick-lru/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From a2275481b7291645c2465cfedaee6bf9332d330a Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Sun, 23 Dec 2018 14:31:58 +0100 Subject: [PATCH 3/3] fix broken tests --- types/got/got-tests.ts | 2 +- types/got/v8/got-tests.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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'));