简体   繁体   English

打字稿定义/创建新类型作为变量?

[英]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. 如果还有其他文件要使用此Object结构,则只需将其导出即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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