Merge pull request #31615 from BendingBender/quick-lru

[quick-lru] Update types to v2
This commit is contained in:
Wesley Wigham
2018-12-24 20:54:58 -08:00
committed by GitHub
9 changed files with 104 additions and 23 deletions
+1 -1
View File
@@ -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'));
+1 -1
View File
@@ -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'));
+3 -3
View File
@@ -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 <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
@@ -7,13 +7,13 @@ export = QuickLRU;
declare class QuickLRU<K, V> 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<K>;
values(): Iterable<V>;
+13 -17
View File
@@ -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<string, number>({ maxSize: 1000 });
new QuickLRU<string, number>(); // $ExpectError
const lru = new QuickLRU<string, number>({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<string, number>
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
}
+1 -1
View File
@@ -21,4 +21,4 @@
"index.d.ts",
"quick-lru-tests.ts"
]
}
}
+26
View File
@@ -0,0 +1,26 @@
// Type definitions for quick-lru 1.1
// Project: https://github.com/sindresorhus/quick-lru#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export = QuickLRU;
declare class QuickLRU<K, V> 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<K>;
values(): Iterable<V>;
}
declare namespace QuickLRU {
interface Options {
maxSize: number;
}
}
+29
View File
@@ -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<string, number>({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;
}
+29
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }