Typescript 无法解析 vscode 中装饰器参数的签名

lul*_*u33 6 typescript visual-studio-code nestjs

当我在 Nestjs 服务中装饰类时收到错误。

Typescript 编译时没有错误,并且我仅在 VSCode 中遇到此问题。

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)
Run Code Online (Sandbox Code Playgroud)

我的 tsconfig

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": false,
    "removeComments": true,
    "strictNullChecks": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "ES2020",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true,
  }
}

Run Code Online (Sandbox Code Playgroud)

我的课

export class AuthService {
  private readonly logger = new Logger('AuthService');
  constructor(
    private readonly jwtService: JwtService,
    private readonly prisma: PrismaService,
    private readonly passwordService: PasswordService,
    private readonly configService: ConfigService,
    private readonly twilioService: TwilioService,
    private readonly userService: UsersService,
    @InjectQueue('nest-worker') private nestWorkerQueue: Queue,
    @InjectQueue('mailsend') private mailSend: Queue,
    @Inject(CACHE_MANAGER) protected readonly cacheManager: Cache,
    private readonly mailerService: MailService
  ) {}

Run Code Online (Sandbox Code Playgroud)

我尝试重新安装打字稿删除节点模块,但问题仍然存在。

小智 11

检查您的扩展。对我来说,删除“JavaScript 和 TypeScript Nightly”扩展解决了这个问题。

  • 我必须在 VS Code 中选择正确的打字稿版本 (2认同)

小智 6

我遇到了与此错误相同的问题:“作为表达式调用时无法解析类装饰器的签名。运行时将使用 2 个参数调用装饰器,但装饰器需要 1”。
对我有用的修复是:

  1. 打开 vscode 命令面板
  2. 输入“选择 TypeScript 版本”
  3. 选择“使用工作区版本”