mmkal / handy-redis

A wrapper around node_redis with Promise and TypeScript support.
Apache License 2.0
172 stars 10 forks source link

Cannot redeclare block-scoped variable 'addCommand' #310

Closed CanTheAlmighty closed 3 years ago

CanTheAlmighty commented 3 years ago

Hi, I just moved from tedis to this library with very few issues, but I'm getting a compile time issue:

Cannot redeclare block-scoped variable 'addCommand'

To isolate the issue, I created an empty typescript project:

{
  "name": "crashy",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "@types/node": "^15.14.0",
    "handy-redis": "^2.2.1",
    "redis": "^3.1.2",
    "typescript": "^4.3.5"
  }
}

With the above, the dependencies currently are (yarn.lock summarized):

// Format
// Package file : Installed Version
@types/redis@^2.8.27:  version "2.8.30"
redis@^3.1.2: version "3.1.2"
handy-redis@^2.2.1: version "2.2.1"

And used a very generic typescript config file.

With all of the above, I get the following conflict:


1410 export function addCommand(command: string): void;
                     ~~~~~~~~~~

  node_modules/handy-redis/dist/node_redis/index.d.ts:5:11
    5     const addCommand: (name: string) => void;
                ~~~~~~~~~~
    'addCommand' was also declared here.

node_modules/handy-redis/dist/node_redis/index.d.ts:5:11 - error TS2451: Cannot redeclare block-scoped variable 'addCommand'.

5     const addCommand: (name: string) => void;
            ~~~~~~~~~~

  node_modules/@types/redis/index.d.ts:1410:17
    1410 export function addCommand(command: string): void;
                         ~~~~~~~~~~
    'addCommand' was also declared here.
CanTheAlmighty commented 3 years ago

I went to the DefinitleTyped repo (aka @types/redis) and there was this very interesting commit 8 days ago (since time of posting):

https://github.com/DefinitelyTyped/DefinitelyTyped/commit/fa3bd98507d1c677b63f4effce230b153fff4403#

  • move add_command to correct location

This seems to be the source of the clash, as addCommand was moved from RedisClient.addCommand to a top-level function

CanTheAlmighty commented 3 years ago

Opened a PR: https://github.com/mmkal/handy-redis/pull/311

UrielCh commented 3 years ago

same issue, I'll rolling back to handy-redis 1.8.3, waiting for a new version.

CanTheAlmighty commented 3 years ago

same issue, I'll rolling back to handy-redis 1.8.3, waiting for a new version.

Alternatively, you can manually change yarn.lock and force it to keep the older version of the package


"@types/redis@^2.8.27":
  version "2.8.27"
  resolved "https://registry.yarnpkg.com/@types/redis/-/redis-2.8.27.tgz#9bc89b472f3fc4a57a06c1823f2fc860c6c2fdf3"
  integrity sha512-RRHarqPp3mgqHz+qzLVuQCJAIVaB3JBaczoj24QVVYu08wiCmB8vbOeNeK9lIH+pyT7+R/bbEPghAZZuhbZm0g==
  dependencies:
    "@types/node" "*"```
mmkal commented 3 years ago

Fixed by #311, released in v2.2.2.