Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Keyv.Options type incorrectly defines store option type #405

Merged
merged 2 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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[]>;
jaredwray marked this conversation as resolved.
Show resolved Hide resolved
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