1

I am trying to create an interface for the following object in angular 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; colour: false; showWireframe: false; showGrid: true; clipping: { enabled: false;...' is not assignable to type 'IRenderState'. Types of property 'clipping' are incompatible. Type '{ enabled: false; visible: false; planes: [{ name: string; plane: Plane; object: null; enabled: t...' is not assignable to type '{ enabled: boolean; visible: boolean; planes: [IPlane, IPlane, IPlane]; }'. Types of property 'planes' are incompatible. Type '[{ name: string; plane: Plane; object: null; enabled: true; flip: false; size: [number, number]; ...' is not assignable to type '[IPlane, IPlane, IPlane]'. Type '{ name: string; plane: Plane; object: null; enabled: true; flip: false; size: [number, number]; }' is not assignable to type 'IPlane'. Types of property 'size' are incompatible. Type '[number, number]' is not assignable to type '[0, 0]'. Type 'number' is not assignable to type '0'.)

I cannot understand what I am doing wrong.

4
  • 2
    In your IPlane interface, object:object rather than object:{} Commented Apr 7, 2017 at 10:01
  • 1
    Dear John, thank you for your answer but the object: object; declaration gives the error cannot find the name object. Commented Apr 7, 2017 at 10:18
  • 1
    OK John, all it needed was to declare object:Object capital O. If you put your comment into a proper answer I am happy to accept your solution and upvote it. Again, thank you very much for your help Commented Apr 7, 2017 at 10:35
  • 1
    @Dino the object type was introduced in TypeScript 2.2, so you will need to upgrade to use it. Worth noting that Object and object are different! Commented Apr 7, 2017 at 12:57

1 Answer 1

1

Typescript 2.2 Has "object" type (all lower). It is recommended to use this one from now.

interface IPlane {
    object: object;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.