Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript error "Unable to resolve signature of parameter decorator when called as an expression" #1667

Closed
ozelen opened this issue Mar 9, 2023 · 13 comments · Fixed by #1685
Labels

Comments

@ozelen
Copy link

ozelen commented Mar 9, 2023

On the sample code:

import { Injectable } from '@nestjs/common';
import { Counter } from 'prom-client';
import { InjectMetric } from '@willsoto/nestjs-prometheus';

@Injectable()
export class Service {
  constructor(@InjectMetric('metric_name') public counter: Counter<string>) {}
}

TS compiler throws an error:

Unable to resolve signature of parameter decorator when called as an expression.
  Argument of type 'typeof Service' is not assignable to parameter of type 'Record<string, unknown>'.
    Index signature for type 'string' is missing in type 'typeof Service'
@willsoto
Copy link
Owner

willsoto commented Mar 9, 2023

What version of TypeScript?

@ozelen
Copy link
Author

ozelen commented Mar 13, 2023

@willsoto , 4.3.5

@willsoto
Copy link
Owner

Works for me on TS 4.9.5

4.3.5 is a very old version of TypeScript though. You should try upgrading and, if it's still broken, creating a minimal reproduction or a failing test case.

@ozelen
Copy link
Author

ozelen commented Mar 13, 2023

Agree. I updated TS version. Still see the error, but it's only visible in VSCode, not runtime. Like follows
image

@willsoto
Copy link
Owner

Try reloading VSCode?

@ozelen
Copy link
Author

ozelen commented Mar 13, 2023

tried already, didn't help though. Weird thing...

@willsoto
Copy link
Owner

Perhaps VSCode isn't using whatever tsconfig the runtime is using?

@ozelen
Copy link
Author

ozelen commented Mar 13, 2023

Looks like the plugin JavaScript and TypeScript Nightly works incorrectly. When I turned it off, the problem disappeared (along with some validation hinting though :), but VSC started performing much better).

@willsoto
Copy link
Owner

👍

@nstoya
Copy link

nstoya commented Mar 31, 2023

With typescript v5 it fails with the same error when trying to build.

@willsoto
Copy link
Owner

Please confirm it's not the same issue with the same resolution mentioned here: #1667 (comment)

If you believe it's actually an issue with v5, please open a new issue with a minimal reproduction of the problem.

@Nicklason
Copy link
Contributor

Please confirm it's not the same issue with the same resolution mentioned here: #1667 (comment)

If you believe it's actually an issue with v5, please open a new issue with a minimal reproduction of the problem.

I have the same problem. This reproduces the problem. I have also fixed the problem and I am making a pull request for it right now.

willsoto pushed a commit that referenced this issue Apr 7, 2023
I found this issue #1667 that had the same errors as me, but the comments didn't help. I also found a different issue nestjs/nest#10959, and the fix they used nestjs/nest#10970, and used that to fix the problem with the InjectMetric decorator.

The problem is that the decorator types are wrong. Record<string, unknown> fails with strict checks, and the key may also be undefined.

Fixes #1667
willsoto pushed a commit that referenced this issue Apr 7, 2023
## [5.1.1](v5.1.0...v5.1.1) (2023-04-07)

### Bug Fixes

* decorator types ([#1685](#1685)) ([6f8a52e](6f8a52e)), closes [#1667](#1667)
@willsoto
Copy link
Owner

willsoto commented Apr 7, 2023

🎉 This issue has been resolved in version 5.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants