-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
redis: add adapter level type generic (#1252)
* feat: add adapter level type generic * test: add type tests --------- Co-authored-by: Jared Wray <me@jaredwray.com>
- Loading branch information
1 parent
fb9a5c5
commit 5edb8c0
Showing
4 changed files
with
80 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import {describe, test, expectTypeOf} from 'vitest'; | ||
import KeyvRedis from '../src/index.js'; | ||
|
||
describe('KeyvRedis Types', () => { | ||
test('should be able to set adapter-level generic value type', async () => { | ||
type Value = {foo: string}; | ||
|
||
const keyvRedis = new KeyvRedis<Value>(); | ||
|
||
expectTypeOf(keyvRedis.get('foo')).toEqualTypeOf< | ||
Promise<Value | undefined> | ||
>(); | ||
|
||
expectTypeOf(keyvRedis.getMany(['foo', 'bar'])).toEqualTypeOf< | ||
Promise<Array<Value | undefined>> | ||
>(); | ||
|
||
expectTypeOf(keyvRedis.iterator()).toEqualTypeOf< | ||
AsyncGenerator<[string, Value | undefined], void, unknown> | ||
>(); | ||
}); | ||
|
||
test('should be able to set method-level generic value type', async () => { | ||
type ValueFoo = {foo: string}; | ||
|
||
type ValueBar = {bar: string}; | ||
|
||
const keyvRedis = new KeyvRedis<ValueFoo>(); | ||
|
||
expectTypeOf(keyvRedis.get<ValueBar>('foo')).toEqualTypeOf< | ||
Promise<ValueBar | undefined> | ||
>(); | ||
|
||
expectTypeOf(keyvRedis.getMany<ValueBar>(['foo', 'bar'])).toEqualTypeOf< | ||
Promise<Array<ValueBar | undefined>> | ||
>(); | ||
|
||
expectTypeOf(keyvRedis.iterator<ValueBar>()).toEqualTypeOf< | ||
AsyncGenerator<[string, ValueBar | undefined], void, unknown> | ||
>(); | ||
}); | ||
}); |