Repository navigation
Closed as not planned
Labels
area: migrationsIssues related to `ng update`/`ng generate` migrationsopen for contributionsAn issue that is suitable for a community contributor (based on its complexity/scope).
Milestone
Description
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
Metadata
Metadata
Assignees
Labels
area: migrationsIssues related to `ng update`/`ng generate` migrationsopen for contributionsAn issue that is suitable for a community contributor (based on its complexity/scope).
Activity
JeanMeche commentedon Jun 10, 2025
Just to be sure, can you give use the type definitions of
StorageSchemaandstorageSchemaToken.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.
aliabodaraa commentedon Jun 10, 2025
Hi there! 👋
I’d like to work on this issue
MeAkib commentedon Jun 11, 2025
Anyone can work on this. Just do it as soon as possible.
JeanMeche commentedon Jun 11, 2025
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 anywhich 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.
angular-automatic-lock-bot commentedon Jul 12, 2025
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.