Skip to content

Commit

Permalink
Fix Keyv.Options type incorrectly defines store option type (#405)
Browse files Browse the repository at this point in the history
* Reproduce bad Store types issue

* Fix Keyv.Options type incorrectly defines store option type
  • Loading branch information
dylanseago authored Jul 19, 2022
1 parent 6e26269 commit 4efe8e0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/keyv/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ declare namespace Keyv {
/** The connection string URI. */
uri?: string | undefined;
/** The storage adapter instance to be used by Keyv. */
store?: Store<Value> | undefined;
store?: Store<string | undefined> | undefined;
/** Default TTL. Can be overridden by specififying a TTL on `.set()`. */
ttl?: number | undefined;
/** Specify an adapter to use. e.g `'redis'` or `'mongodb'`. */
Expand Down
11 changes: 9 additions & 2 deletions packages/redis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@
"xo": {
"rules": {
"unicorn/prefer-module": 0,
"unicorn/prefer-node-protocol": 0
"unicorn/prefer-node-protocol": 0,
"ava/no-ignored-test-files": ["error", {"extensions": ["js", "ts"]}]
}
},
"ava": {
"require": [
"requirable"
"requirable",
"ts-node/register"
],
"extensions": [
"js",
"ts"
]
},
"repository": {
Expand Down Expand Up @@ -51,6 +57,7 @@
"nyc": "^15.1.0",
"requirable": "^1.0.5",
"this": "^1.1.0",
"ts-node": "^10.8.2",
"tsd": "^0.22.0",
"typescript": "^4.7.4",
"xo": "^0.50.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/redis/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ declare class KeyvRedis extends EventEmitter implements Store<string | undefined
constructor(options?: KeyvRedis.Options | Redis | Cluster);
constructor(uri: string | Redis | Cluster, options?: KeyvRedis.Options);
get(key: string): Promise<string | undefined>;
getMany(keys: string[]): Promise<string[] | undefined>;
getMany(keys: string[]): Promise<string[]>;
set(key: string, value: string | undefined, ttl?: number): Promise<any>;
delete(key: string): boolean;
deleteMany(keys: string[]): boolean;
Expand Down
18 changes: 18 additions & 0 deletions packages/redis/test/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import test from 'ava';
import Keyv from 'keyv';
import KeyvRedis from '../src/index.js';

const redisHost = 'localhost';
const redisUri = `redis://${redisHost}`;

type MyType = {
a: string;
};

test('can specify redis store in typescript', async t => {
const keyv = new Keyv<MyType>({
store: new KeyvRedis(redisUri),
});

t.true(await keyv.set('testkey', {a: 'testvalue'}));
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
// "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */

Expand Down

0 comments on commit 4efe8e0

Please sign in to comment.