suppose i imported a namespace in typescript , lets call it ui
, and it has one more namespace called dates
and then there is one interface called IDateFormat
, but only ui
is exported
so if I have to consume the interface i have to do
import {ui} from '..pathToFile'
//to use interface i have to do
const format : ui.dates.IDateFormat
so basically i have to write ui.dates.IDateFormat
every time
can i shorten it by assigning to a variable.
like
const intrface : < what's the type> = ui.dates.IDateFormat; // will this work
and use it
but i was thinking what will be the type of such variable and is there any other way to do it?
You can just export it from your own module like this:
export type shortType = ui.dates.IDateFormat;
export interface shortInterface extends ui.dates.IDateFormat {
}
What you are looking for is a type alias . It doesn't use a const
declaration:
type Intrface = ui.dates.IDateFormat;
const format : Intrface = …;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.