Skip to content

Tighter parameter decorator checking with --experimentalDecorators #52435

Description

// @experimentalDecorators: true
export declare const Inject:
  (entity: Function, dataSource?: string) =>
    (target: object, key: string | symbol, index?: number) => void;

export class Foo {}

export class C {
  constructor(@Inject(Foo) x: any) {  }
}

Previously: no error
In main/5.0:

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'

Activity

  1. DanielRosenwasser commented on Jan 26, 2023

    @DanielRosenwasser
    MemberAuthor

    Was this...possibly always a bug with --experimentalDecorators?

  2. changed the title [-]Decorator call resolution regression with `--experimentalDecorators`[/-] [+]Decorator call regression with `--experimentalDecorators`[/+] on Jan 26, 2023
  3. DanielRosenwasser commented on Jan 26, 2023

    @DanielRosenwasser
    MemberAuthor

    Yes, it seems this was a bug in type-checking parameter decorators on constructors under --experimentalDecorators with TypeScript 4.9 and prior.

    In #50820, we fixed up the way we type-checked decorators. This catches some issues, like decorators which expect a defined key; however, parameter decorators in constructors don't get passed a key. As a result, libraries with dependency injection decorator functions like inversify (pre-6.0), NestJS, and others (often named inject, Inject, and InjectRepository) might need to be corrected to accept an undefined key (or to have an overload which accepts an undefined key).

  4. changed the title [-]Decorator call regression with `--experimentalDecorators`[/-] [+]Tighter parameter decorator checking with `--experimentalDecorators`[/+] on Jan 26, 2023
  5. rbuckton commented on Jan 26, 2023

    @rbuckton
    Contributor

    inversify's @inject works fine starting in [email protected]. @nestjs/common's @inject needs to be updated, however.

  6. kevinlul commented on Jan 27, 2023

    @kevinlul

    Is tsyringe affected?

  7. DanielRosenwasser commented on Jan 27, 2023

    @DanielRosenwasser
    MemberAuthor
  8. DanielRosenwasser commented on Jan 27, 2023

    @DanielRosenwasser
    MemberAuthor

    I filed an issue at NestJS over at #52435. I'm not sure how active TSyringe is at the moment.

  9. typescript-bot commented on Jan 29, 2023

    @typescript-bot
    Contributor

    This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

  10. Evaldoes commented on Jan 7, 2024

    @Evaldoes

    I was able to solve this problem by adding these parameters to the tsconfig.json file:

    I used inversify: 6.0.1 version

    NOTE: when I inserted it at the end of the file it didn't work, only when I put it at the beginning

    {
      "compilerOptions": {
          "emitDecoratorMetadata": true,
          "experimentalDecorators": true,
          "allowJs": true,
      }
    }
    

    I hope I can help 😄

  11. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Breaking ChangeWould introduce errors in existing codeWorking as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions