[英]How can i shorten name of interface in typescript?
假设我在typescript中导入了一个名称空间,让我们称之为ui
,它还有一个名为dates
名称空间,然后有一个名为IDateFormat
接口,但只导出了ui
所以,如果我必须消耗我必须做的接口
import {ui} from '..pathToFile'
//to use interface i have to do
const format : ui.dates.IDateFormat
所以基本上我每次都要写ui.dates.IDateFormat
我可以通过分配变量来缩短它。
喜欢
const intrface : < what's the type> = ui.dates.IDateFormat; // will this work
并使用它
但我在想什么是这种变量的类型,还有其他方法吗?
你可以从你自己的模块中导出它,如下所示:
export type shortType = ui.dates.IDateFormat;
export interface shortInterface extends ui.dates.IDateFormat {
}
您正在寻找的是类型别名 。 它不使用const
声明:
type Intrface = ui.dates.IDateFormat;
const format : Intrface = …;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.