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

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

问题描述

在打字稿中,使用 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天全站免登陆