Skip to content

Instantly share code, notes, and snippets.

@xesjkeee
Last active September 24, 2020 11:23
Show Gist options
  • Save xesjkeee/b94bca7ca86c91bbd05de806aff5d01b to your computer and use it in GitHub Desktop.
Save xesjkeee/b94bca7ca86c91bbd05de806aff5d01b to your computer and use it in GitHub Desktop.
async-redis: Add export interface
// For example, I use Dependency Injection pattern in my architecture of node.js app
import asyncRedis from 'async-redis'
import { Container } from 'typedi'
const client = asyncRedis.createClient(config.redis)
Container.set('redis', client)
import { Service, Inject } from 'typedi'
@Service()
export default class Animal {
constructor (
@Inject('redis') private redis: any // <-- problem here, i can't set type of redis client
) {}
async getAll () {
// this.redis is any and set-method is too any
await this.redis.set('foo', 'bar')
}
}
// What I expecting
import { Service, Inject } from 'typedi'
import { Promisified, RedisClient } from 'async-redis'
@Service()
export default class Animal {
constructor (
@Inject('redis') private redis: Promisified<RedisClient> // <-- here i can validate type-chicking
) {}
async getAll () {
await this.redis.set('foo', 'bar')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment