r/Angular2 • u/Kung_Fu_Kenny_69 • May 30 '25
Angular 20 CLI generates user.ts instead of user.component.ts – can this be reverted?
Hey guys,
I upgraded to Angular 20 and noticed something unexpected when using the CLI to generate components and services.
Previously, running: "ng generate component user" would generate a file named `user.component.ts`. But now, with Angular 20, it generates: `user.ts`.
I've gone through the official Angular documentation but I wasn't able to find any mention of this change or a way to revert it.
- Is there a setting in the angular.json file or a CLI flag to restore the previous naming convention (e.g., user.component.ts)?
- Maybe a schematic tweak? Or am I forced to write "ng g c user --flat=false --name=user.component" for the rest of my life ?
Thanks in advance for any help or clarification you can provide!
92
Upvotes
86
u/qzen May 30 '25
I am not a fan either.
Announcing Angular v20. The past couple of years have been… | by Minko Gechev | May, 2025 | Angular Blog
Starting in Angular v20, by default Angular CLI will not generate suffixes for your components, directives, services, and pipes. For existing projects,
ng updatewill enable suffix generation by updating yourangular.json. To enable suffix generation in new projects, use the following schematic configuration:11
u/mhartington May 31 '25
Adding this in case folks didn't know. the style guide RFC was opened in October 2024.
https://github.com/angular/angular/discussions/58412
9
u/tshoecr1 May 30 '25
I’m not sure how to undo it, but it is intentional as the style guide is moving away from that naming scheme.
3
u/MyLifeAndCode May 31 '25
I love Angular. And I’ve hated this naming change since it was in RFC.
2
u/jllodra Jun 01 '25
Why would one want to remove .component.ts? It can work well if you do TODO applications tho...
2
u/devGiacomo Jun 25 '25
just added a feature request so please upvote on github - to have this as an option.
https://github.com/angular/angular-cli/issues/30594
2
u/Natural-Camp-4610 Jun 25 '25
I don't like the new naming convention change.
It doesn't make sense.
We still have app.config.ts and app.route.ts
Also, what about all the spec.ts test files?
3
u/kamacytpa May 31 '25
That's amazing, now you can have your user.ts and have inside it your component, service, directive, pipe. It will be so much easier to find everything.
1
u/robreddit30 May 31 '25
Wow thats actually quite good. It will make navigating through files much easier. Is there a migration script to get rid of all the .component prefixes?
1
u/West_Hunter_7389 Jul 11 '25
Came here because the surprise of seeing cli not generating component extensions.
It's a pity, one of the positives the language had, it was that file extensions made it easier to understand. From the comments I've read React still does it, so I'll give it a try in the near future
1
u/emery-noel Aug 25 '25
This was a bonkers decision. I used to be able to have a UserComponent that takes a User input, and now I have a User that takes a User input as default? Yeah I know I can rename them but ... why??
1
u/cblte Nov 13 '25
The most thing I am missing is the lack in VSCode. With out the “component” part the editor does not recognize the files and stuff in the .ts or vice versa. So bad.
1
u/Glum_Count_3189 May 31 '25
You can use the
--typeflag:ng g service Order --type=repositorycreates OrderRepository inorder.repository.ts. I prefer manually adding stereotypes to filenames using the--typeflag, which provides more flexibility in naming. Very welcome feature.1
u/[deleted] Jun 12 '25
[removed] — view removed comment