[英]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.