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

廉价感情. 提交于 2019-12-22 03:18:41

问题


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?


回答1:


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

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


来源:https://stackoverflow.com/questions/40675222/name-collision-by-module-import-in-angular-2-is-there-a-way-to-prevent-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!