Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Name collision by module import in Angular 2 - is there a way to prevent it

I've almost caused a name collision, because I've created a class with common name Message, which already exists in PrimeNG:

import {Message} from "primeng/primeng";
import {Message} from "./dto";

Because it is my code, I could simply rename the class to anything else (like MessageDTO). But if this was the external class, I'd have an issue.

Is there any way to import class with alias, or any other mean to deal with name conflicts? I Java you can refer to class using fully qualified name instead of import, which looks ugly but is often unavoidable. How it looks like in Angular 2/TypeScript?

like image 940
9ilsdx 9rvj 0lo Avatar asked Nov 18 '16 10:11

9ilsdx 9rvj 0lo


People also ask

What is AppModule ts in Angular?

Tell Angular how to construct and bootstrap the app in the root "AppModule". An Angular module class describes how the application parts fit together. Every application has at least one Angular module, the root module that you bootstrap to launch the application.

Why we use BrowserModule in Angular?

BrowserModule provides services that are essential to launch and run a browser application. BrowserModule also re-exports CommonModule from @angular/common , which means that components in the AppModule also have access to the Angular directives every application needs, such as NgIf and NgFor .

What is declarable in Angular?

Declarables allow the angular compiler to know which module will actually contain the component, directive or pipe. As the compiler generates the factories that make the views, it will integrate those components with the module they were declared, and only refer to them in any other module that might be using them.

What are NgModules?

NgModules consolidate components, directives, and pipes into cohesive blocks of functionality, each focused on a feature area, application business domain, workflow, or common collection of utilities. Modules can also add services to the application.


1 Answers

As per TypeScript import document imports can also be renamed same as below :

import { Message } from "primeng/primeng";
import { Message as MessageDTO } from "./dto";
like image 78
ranakrunal9 Avatar answered Sep 17 '22 19:09

ranakrunal9