简体   繁体   中英

typescript define/create new type as a variable?

I have this type

{timeStamp: number, rectangle:number[]}

and I want to use it multiple times(within the same file), is there any way to do it like:

type detectionParams = {timeStamp: number, rectangle:number[]};
private detection: detectionParams[];

Since you have a plain object type, rather than using the type alias its more common to use an interface instead.

interface DetectionParams {
    timeStamp: number;
    rectangle: number[];
};

If any other files are to use this Object structure, just export it.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM