Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
typescript是否定义/创建新类型作为变量?_Typescript - Fatal编程技术网

typescript是否定义/创建新类型作为变量?

typescript是否定义/创建新类型作为变量?,typescript,Typescript,我有这种类型的 {timeStamp: number, rectangle:number[]} 我想多次使用它(在同一个文件中), 有没有办法做到这一点,比如: type detectionParams = {timeStamp: number, rectangle:number[]}; private detection: detectionParams[]; 因为您有一个普通的对象类型,而不是使用类型别名,所以更常见的做法是使用接口 interface DetectionParams {

我有这种类型的

{timeStamp: number, rectangle:number[]}
我想多次使用它(在同一个文件中), 有没有办法做到这一点,比如:

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

因为您有一个普通的对象类型,而不是使用类型别名,所以更常见的做法是使用接口

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

如果任何其他文件要使用此对象结构,只需将其导出。

实际上与此完全相同。注意,惯例是类型以大写字母开头,因此
类型检测参数=…
会更好。哦,我只是把它放错了位置。。。谢谢你的安慰。