4
import * as redis from 'redis'
import config from '../../config/config'
const client = redis.createClient(config.redis.port, host, config.redis.options);
client.on('ready', () => {
  console.log('redis is ready.')
});

getting below error in typescript

[ts] Property 'on' does not exist on type '{ address: any; connection_options: { [x: string]: any; }; connection_id: number; connected: bool...'. any

1
  • Installed @types/redis? Commented Mar 5, 2018 at 15:42

2 Answers 2

2

First of all, have you installed the type module for the redis module? I highly recommend doing that as it helps TypeScript compiler and potentially your IDE to know what commands and interfaces are available in the redis module. To do so:

npm i --save-dev @types/redis

Second, try adding the .on('error', console.error) to see if your client is emitting any meaningful connection errors. There could be a problem with you client credentials, which fails the connections.

Lastly, you can completely skip the .on('ready', ...) event handler as it's not necessary. The redis module queues all the commands sent before the connection is established, and will automatically send them once it's successfully connected. You can just start testing the client with simple set and get commands.

Sign up to request clarification or add additional context in comments.

2 Comments

I am trying the same but facing following issue, ERROR Error: Uncaught (in promise): TypeError: net.isIP is not a function TypeError: net.isIP is not a function.
@Tejal Can you provide the context? Including the code that causes the error?
0

I encountered the same problem. Everything seemed fine, redis typings were installed (actually already provided by the redis package).

However, I simply forgot to install the nodejs types... Without these typing, typescript isn't aware of, i.a, the EventEmitter.

Try installing:

npm install --save-dev @types/node

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.