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[];
};
如果任何其他文件要使用此对象结构,只需将其导出。实际上与此完全相同。注意,惯例是类型以大写字母开头,因此
类型检测参数=…
会更好。哦,我只是把它放错了位置。。。谢谢你的安慰。