Efim Rozovsky
Efim Rozovsky

Reputation: 1327

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[];

Upvotes: 0

Views: 54

Answers (1)

Nugu
Nugu

Reputation: 848

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.

Upvotes: 1

Related Questions