简体   繁体   English

打字稿界面

[英]Typescript interfaces

I am trying to create an interface for the following object in angular 2: 我试图为角度2中的以下对象创建接口:

// set the render state object
    this.aRenderState = {
      model: "",
      colour: false,
      showWireframe: false,
      showGrid: true,
      clipping: {
          enabled: false,
          visible: false,
          planes: [
              {
                  name: 'X',
                  plane: new THREE.Plane(new THREE.Vector3(1, 0, 0), 0),
                  object: null,
                  enabled: true,
                  flip: false,
                  size: [this.aDomain.getSize().z, this.aDomain.getSize().y],
              },
              {
                  name: 'Y',
                  plane: new THREE.Plane(new THREE.Vector3(0, 1, 0), 0),
                  object: null,
                  enabled: false,
                  flip: false,
                  size: [this.aDomain.getSize().x, this.aDomain.getSize().z]
              },
              {
                  name: 'Z',
                  plane: new THREE.Plane(new THREE.Vector3(0, 0, -1), 0),
                  object: null,
                  enabled: false,
                  flip: false,
                  size: [this.aDomain.getSize().x, this.aDomain.getSize().y]
              },
          ]
      }
    }

the following is my attempt: 以下是我的尝试:

export interface IPlane {
  name: string;
  plane: THREE.Plane;
  object: {};
  enabled: boolean;
  flip: boolean;
  size: number[];
}

export interface IClipping {
  enabled: boolean;
  visible: boolean;
  planes: IPlane[];
}

export interface IRenderState {
  model: string;
  colour: boolean;
  showWireframe: boolean;
  showGrid: boolean;
  clipping: IClipping;
}

when i run the project I get the following error message: 当我运行项目时,出现以下错误消息:

Type '{ model: string; 类型'{model:string; colour: false; 颜色:假; showWireframe: false; showWireframe:假; showGrid: true; showGrid:true; clipping: { enabled: false;...' is not assignable to type 'IRenderState'. 裁剪:{启用:否; ...”不能分配给类型“ IRenderState”。 Types of property 'clipping' are incompatible. 属性“剪切”的类型不兼容。 Type '{ enabled: false; 输入'{enabled:false; visible: false; 可见:错误; planes: [{ name: string; 飞机:[{名称:字符串; plane: Plane; 飞机 object: null; 对象:null; enabled: t...' is not assignable to type '{ enabled: boolean; 启用:t ...”不能分配给类型“ {启用:布尔值; visible: boolean; 可见:布尔值; planes: [IPlane, IPlane, IPlane]; 平面:[IPlane,IPlane,IPlane]; }'. }”。 Types of property 'planes' are incompatible. 属性“平面”的类型不兼容。 Type '[{ name: string; 输入'[{name:string; plane: Plane; 飞机 object: null; 对象:null; enabled: true; 已启用:true; flip: false; 翻转:错误; size: [number, number]; 大小:[数字,数字]; ...' is not assignable to type '[IPlane, IPlane, IPlane]'. ...”不能分配给类型[[IPlane,IPlane,IPlane]”。 Type '{ name: string; 输入'{name:string; plane: Plane; 飞机 object: null; 对象:null; enabled: true; 已启用:true; flip: false; 翻转:错误; size: [number, number]; 大小:[数字,数字]; }' is not assignable to type 'IPlane'. }”不可分配给“ IPlane”类型。 Types of property 'size' are incompatible. 属性“大小”的类型不兼容。 Type '[number, number]' is not assignable to type '[0, 0]'. 类型“ [数字,数字]”不能分配给类型“ [0,0]”。 Type 'number' is not assignable to type '0'.) 类型“数字”不能分配给类型“ 0”。)

I cannot understand what I am doing wrong. 我不明白我在做什么错。

Typescript 2.2 Has "object" type (all lower). 打字稿2.2具有“对象”类型(全部较低)。 It is recommended to use this one from now. 建议从现在开始使用此版本。

interface IPlane {
    object: object;
}

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

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