nest-modules / ioredis

:see_no_evil: :hear_no_evil: :speak_no_evil: A ioredis module for Nest framework (node.js)
MIT License
145 stars 31 forks source link

@InjectRedis() Unable to resolve signature of parameter of decorator in vscode #266

Closed cybergitt closed 10 months ago

cybergitt commented 1 year ago

I'm getting the error when I'm decorating the class in nestjs service. I'm using typescript 4.7.4

The Typescript is compiling without errors, and I'm getting this problem only in VS Code.

Unable to resolve signature of parameter decorator when called as an expression. Argument of type 'undefined' is not assignable to parameter of type 'string | symbol'.ts(1239)

for your reference this is my tsconfig:

{
  "compilerOptions": {
    "outDir": "./dist",
    "rootDirs": ["./src", "./test"],
    "baseUrl": "./",
    "paths": {
      "@common/*": ["src/common/*"],
      "@infrastructure/*": ["src/infrastructure/*"],
      "@modules/*": ["src/modules/*"],
      "@shared/*": ["src/shared/*"],
      "@test/*": ["test/*"]
    },
    "target": "ES2020",
    "module": "commonjs",
    "lib": ["ES2020"],
    "types": ["reflect-metadata", "jest", "node"],
    "alwaysStrict": true,
    "strict": true,
    "strictPropertyInitialization": false,
    "allowJs": true,
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": true,
    "noImplicitAny": true,
    "strictBindCallApply": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true
  },
  "include": ["./src/**/*.ts", "./test/**/*.ts"]
}

Service class:

@Injectable()
export class AuthService {
  constructor(
    @InjectRedis() private readonly redis: Redis,
    private readonly sharedService: SharedService,
    private readonly userService: UserService,
  ) {}

  async getHello() {
    await this.redis.set('key', 'Redis data!');
    const redisData = await this.redis.get('key');
    return { redisData };
  }
}

I tried reinstalling typescript and removing the node module, but the problem still remains.

imanhpr commented 1 year ago

I have the same problem and i couldn't find anything to fix it.

imanhpr commented 1 year ago

If you set "strictNullChecks": false in your tsconfig.json, it'll fix your problem. I couldn't find a better solution

aaronovz1 commented 1 year ago

Anyone found a better solution for this?

aaronabf commented 1 year ago

None. The library needs to be patched.

aaronovz1 commented 1 year ago

So instead of turning off strictNullChecks - there is a slightly less dirty option of casting to any:

@((InjectRedis as any)())

aaronabf commented 1 year ago

So instead of turning off strictNullChecks - there is a slightly less dirty option of casting to any:

@((InjectRedis as any)())

This is what we ended up doing. So ugly :(

cybergitt commented 1 year ago

If you set "strictNullChecks": false in your tsconfig.json, it'll fix your problem. I couldn't find a better solution

yeah, for unstrict project this solution is good, thanks dude.

treefitty commented 10 months ago

This is where we're leaving this one? Doesn't seem to be properly resolved IMHO 🤷‍♂️