Interfaces in Typescript

In my Angular 2 project, I am working on creating an interface for a complex object. Here is the code snippet of the object:

// Defining 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]
          },
      ]
  }
}

Here's my attempt at defining interfaces for the above object:

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;
}

However, when I try to run the project, I encounter 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'm struggling to understand where I have made a mistake in my code.

Answer №1

There is a new "object" type in Typescript 2.2 (all lowercase). It is highly advised to start using this type going forward.

interface IPlane {
    object: object;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Setting up the Font Awesome Pro version in Angular using the Font-Awesome package

The process of installing the pro version of Angular Font-awesome began with setting up my registry using these commands: npm config set "@fortawesome:registry" https://npm.fontawesome.com/ && \ npm config set "//npm.fontawesome.com/:_authTo ...

How can I transfer an instance of a class to dataTransfer.setData?

So I created a new instance of a class: let item = new Item(); Next, I attempted to serialize the item and add it to dataTransfer for drag and drop functionality: ev.dataTransfer.setData("info", JSON.stringify(item)); At some point, I need to retriev ...

Extremely sluggish change identification in combination Angular application

We are encountering consistent issues with slow change detection in our hybrid AngularJS / Angular 8 app, especially when dealing with components from different versions of the framework. The problem seems to arise when using older AngularJS components wit ...

Embracing Angular 9 Ivy results in encountering errors

After updating my app to Angular 9, I encountered an issue with Ivy where I receive the error error NG6002: The error logs are as follows - 32 export class FooterModule { } ~~~~~~~~~~~~ src/app/core/ncpapp.core.module.ts:30:14 - error NG6002: ...

Refine the observable data

Trying to filter a list of items from my Firebase database based on location.liked === true has been a challenge for me. I've attempted using the traditional filter array method but have not had success. Can anyone suggest an alternative method to acc ...

Automatically increase the version with Yarn auto Version Bump

My package.json file uses a 4-digit version format like "version": "1.3.0-0". When I run the command yarn version --prerelease on my Windows system, it correctly shows: info Current version: 1.3.0-0 info New version: 1.3.0-1 However, ...

Simple steps for Mocking an API call (Get Todos) using ComponentDidMount in React with Typescript, Jest, and Enzyme

About the application This application serves as a basic To Do List. It retrieves tasks from an API located at https://jsonplaceholder.typicode.com/todos?&_limit=5. Objective of the project The main goal is to test an API call that triggers ...

What changes can be implemented to convert this function to an asynchronous one?

Is it possible to convert the following function into an asynchronous function? getHandledSheet(): void { this.timesheetService.getAllTimesheets().subscribe({next: (response: TimeSheet[]) => {this.timesheetsHandled = response.filter(sheet => ...

Guide on integrating angular-schema-form into an Ionic 2.0 project using typescript

Recently, I embarked on creating an app with Ionic from scratch and decided to integrate the framework. While I faced no issues executing the example on a webpage, I encountered difficulties when attempting to do so with Ionic. To kickstart the project, ...

Creating a TypeScript declaration file for a singular module

Consider the following directory structure: src/ ├── foo.ts ├── bar.ts ├── baz.ts ├── index.ts If foo.ts, bar.ts, and baz.ts each export a default class or object, for example in foo.ts: export default class Foo { x = 2; } I ...

Convert the XML response from an API into JSON

Is there a way to convert my XML response into JSON using Angular? This is the response I am working with: <?xml version="1.0" encoding="utf-8"?> <string xmlns="http://tempuri.org/"><?xml version="1.0" encoding="utf-8"?&gt; &lt;Fer ...

Anticipated the object to be a type of ScalarObservable, yet it turned out to be an

When working on my Angular project, I utilized Observables in a specific manner: getItem(id): Observable<Object> { return this.myApi.myMethod(...); // returns an Observable } Later, during unit testing, I successfully tested it like so: it(&apos ...

How to assign ngModel to a nested component in Angular?

If I have a component called InputComponent, which implements the ControlValueAccessor interface. Now, another component named AnotherComponent uses the InputComponent like this: <my-input [(ngModel)]="text"></my-input> While testing AnotherC ...

Leveraging the power of the Async pipe within an Angular TypeScript file

Using the async pipe in HTML involves utilizing the syntax "Products$ | async as products". But can we also access these same products in the TypeScript file? Is this possible? ...

Offset the CDK Menu

Is it possible to adjust the position of the trigger using the CDK overlay by setting an offset (e.g. cdkConnectedOverlayOffsetY)? I've looked through the CDK menu documentation but couldn't find a similar functionality. Is there a method to achi ...

What steps can I take to adapt my component in order to incorporate RxJs?

I am trying to gain proficiency in RxJs and, for educational purposes, I am interested in understanding how to modify the following code or if it is even feasible. Within my project, there is a component called MeetingObjectComponent which contains a chil ...

How do you verify an OpenID Connect access token produced by Azure AD v2 in an ASP.NET Core web API?

What is the best way to verify an OpenID Connect Access Token generated by Azure AD (v2) in ASP.NET Core Web API? Here's the situation: I have an Angular 8 Client Application that receives an OpenID Connect access Token post Login. The Client can us ...

Having trouble with Visual Studio 2015 not compiling TypeScript within an ASP.NET Core project?

Seeking assistance with my Angular app development setup in VS2015. Even though it is recognized as a TypeScript Virtual Project, I am facing issues getting the transpiled files into the wwwroot folder within my ASP.NET Core project. Here's an overvie ...

What is the process of unloading pages in Angular 2?

In the process of developing an Angular 2 application consisting of approximately 200 pages, we have considered various loading strategies such as lazy loading, eager loading, and pre-loading. A question that arises is whether a page that has been lazily ...

The type 'string | AddressInfo' does not include a 'port' property and does not have a string index signature

When running in { port }, I encountered the following error: Type 'string | AddressInfo' has no property 'port' and no string index signature. How can I resolve this issue? Code: import * as express from 'express' const app ...