导入两个具有相同名称的导出类 [英] Import two exported classes with the same name

查看:91
本文介绍了导入两个具有相同名称的导出类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在打字稿中,使用Angular 2,我需要导入两个具有相同名称但位于不同路径的类.

In typescript, using Angular 2, I need to import two classes with the same name, but lying in different paths.

该项目太大,以至于我很难更改导出的类名.

The project is quite too big that I find it hard to change the exported class names.

有什么办法别名导入的类吗?

Is there any way to alias the imported classes,

import {Class1} from '../location1/class1'
import {Class1} from '../location2/class1'

推荐答案

您可以像这样使用as:

import {Class1} from '../location1/class1'
import {Class1 as Alias} from '../location2/class1'

您可以在此处找到更多有关ES6导入语句的信息. .

这篇关于导入两个具有相同名称的导出类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆