Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I give an alias to an imported library in angular/typescript?

I'm having troubles with the following. I have been working for a while with a model called Location, but now I found that angular also has such a model so I have the following collision in one component where I need both:

import { Location } from 'src/app/core/models/location.model';
import { Location }  from '@angular/common';

Is there any workaround for this such as giving an alias to the library?

Current issue:

Duplicate identifier 'Location'.ts(2300)

like image 594
nck Avatar asked Jan 22 '26 17:01

nck


1 Answers

You can alias imports using the as keyword to avoid name collisions.

import { Location as LocationModel } from 'src/app/core/models/location.model';
import { Location }  from '@angular/common';
like image 183
Joey Kilpatrick Avatar answered Jan 25 '26 07:01

Joey Kilpatrick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!