I have two types with the same name I need to import into a component.
Is something like this acceptable in typescript?
import type { Variant as FooVariant } from '$s/foo/types';
import type { Variant as BarVariant } from '$s/bar/types';
export type CompositeType= {
foo: FooVariant;
bar: BarVariant;
}
If you need it because you are using 2 third-party libs that use the same class/object name, then It's perfectly valid, even necessary. The import rename is documented as part of the language.
On the other hand, if the rename is on your own code then I would change the name in the original file (if that file is part of your project). Exporting the same artifact name in 2 different files (in the same project) It's a source of potential issues, When you try to import with the IDE you need to choose the proper one and It's easy to get wrong, besides the resulting code in the modules that consume that object is not clear, you need to check the import { ... } from '...' line to known what are you using exactly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With