Skip to content

migration @angular/core:inject create uncompiled code #61982

Closed as not planned
Closed as not planned

Description

@sysmat

Command

generate

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

when running ng generate @angular/core:inject generated code is uncompiled

Minimal Reproduction

  • source
constructor(@Inject(storageSchemaToken) @Optional() storage?: StorageSchema) {
  ....
}
  • generated
constructor() {
    const storage = inject<StorageSchema>(storageSchemaToken, { optional: true });
  }

Exception or Error

- compile error


 No overload matches this call.
  Overload 1 of 6, '(token: ProviderToken<StorageSchema>, options: InjectOptions & { optional?: false; }): StorageSchema', gave the following error.
    Argument of type 'string' is not assignable to parameter of type 'ProviderToken<StorageSchema>'.
  Overload 2 of 6, '(token: ProviderToken<StorageSchema>, options: InjectOptions): StorageSchema', gave the following error.
    Argument of type 'string' is not assignable to parameter of type 'ProviderToken<StorageSchema>'.

19     const storage = inject<StorageSchema>(storageSchemaToken, { optional: true });

Your Environment

Angular CLI: 20.0.1
Node: 22.15.0
Package Manager: npm 10.9.2
OS: win32 x64

Angular: 20.0.2
... animations, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.2000.1
@angular-devkit/core         20.0.1
@angular-devkit/schematics   20.0.1
@angular/build               20.0.1
@angular/cli                 20.0.1
@schematics/angular          20.0.1
ng-packagr                   20.0.0
rxjs                         7.8.2
typescript                   5.8.3
zone.js                      0.15.1

Anything else relevant?

No response

Activity

  1. JeanMeche commented on Jun 10, 2025

    @JeanMeche
    Member

    Just to be sure, can you give use the type definitions of StorageSchema and storageSchemaToken.

    Edit: It looks like the issue is with string based tokens which are not recommended anymore (but still supported because of angularjs hybrid apps).

    What the schematics should probably do here : skip the migration for string tokens and log a warning.

  2. added
    open for contributions
    area: migrations
    on Jun 10, 2025
  3. added this to the needsTriage milestone on Jun 10, 2025
  4. aliabodaraa commented on Jun 10, 2025

    @aliabodaraa

    Hi there! 👋
    I’d like to work on this issue

  5. MeAkib commented on Jun 11, 2025

    @MeAkib
    Contributor

    Hi there! 👋 I’d like to work on this issue

    Anyone can work on this. Just do it as soon as possible.

  6. JeanMeche commented on Jun 11, 2025

    @JeanMeche
    Member

    As @JoostK mentionned here, we're kind of hitting a limitation of migration implementation here. The typechecker can't have access to the external files and won't be able to inspect external types.

    The issue you're encountering shouldn't be very common as string token are recommended against and the fix is relatively straightforward (adding as any which is what the migration does when encountering a literal).

    https://github.com/angular/angular/blob/main/packages/core/schematics/ng-generate/inject-migration/migration.ts#L537-L538

    As we consider as acceptable that migration aren't perfect, I think we can close this issue.

  7. angular-automatic-lock-bot commented on Jul 12, 2025

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  8. locked and limited conversation to collaborators on Jul 12, 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

    area: migrationsopen for contributions

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions