node-redis icon indicating copy to clipboard operation
node-redis copied to clipboard

Typescript error: RedisClientType type is missing `on` property

Open chiawendt opened this issue 1 year ago • 2 comments

Description

The RedisClientType type appears to be missing the on method. This causes a type-checking error when using .on to handle events. Below is an example that triggers the error:

import { createClient } from "redis";
const redis = createClient().on("error", (err) => {});
//                           ~~ Property 'on' does not exist on type 'RedisClientType...

Node.js Version

v22.9.0

Redis Server Version

not relevant

Node Redis Version

[email protected]

Platform

not relevant

Logs

No response

chiawendt avatar Nov 30 '24 09:11 chiawendt

having the same issue when using this redis package in my turborepo, i get 'Property 'on' does not exist on type 'RedisClientType'.

however, was able to create a fresh project with bun and run this library with no issues, the issue only happens with pnpm

100xlongx avatar Dec 19 '24 21:12 100xlongx

I was surprised to see typing errors with on and once methods in both mongoose and redis. Downgrading to TS 5.4.5 was a one way to solve the issue, but are you perhaps using discord.js (or other packages depending on it)? They were using module augmentation to change EventEmitter typings, which caused issues after TS 5.5 release. See this. It's been fixed for a while now, and after upgrading the package, typings are working fine with the latest TS installed.

MZPL avatar Dec 24 '24 23:12 MZPL