Resolving TypeScript error: Property 'Error' does not exist on type 'Angular2 and Objects'

One of the models I am working with is called "opcionesautocomplete.model.ts"

interface IOpcionesAutocomplete {
    opcionesStyle: OpcionStyle;  
    pcionPropiedades: OpcionPropiedades;
}

export class OpcionesAutocomplete implements IOpcionesAutocomplete {      
     opcionesStyle: OpcionStyle;
     opcionPropiedades: OpcionPropiedades;
    constructor()  { }
}

interface IOpcionStyle {
    width: number;
    height: number; 
    isOverflowY: boolean;
}

export class OpcionStyle implements IOpcionStyle {
      width: number;
      height: number; 
      isOverflowY: boolean;
    constructor()  { }
}

interface IOpcionPropiedades {
    propiedad1: string;
    propiedad2: string; 
    textoEtiqueta: string;
}

export class OpcionPropiedades implements IOpcionPropiedades {
    propiedad1: string;
    propiedad2: string; 
    textoEtiqueta: string;
    constructor()  { }
}

Currently, I am attempting to populate the object in my component with all its properties. However, Angular2 is throwing an error in "mycmp.component.ts":

import { OpcionesAutocomplete, OpcionStyle, OpcionPropiedades } from './../../shared/forms/autocomplete/opcionesautocomplete.model';

export class.... {

    opcionStyle = new OpcionStyle();
    opcionPropiedades = new OpcionPropiedades();

    opcionesAutocompleteClientes : OpcionesAutocomplete = new OpcionesAutocomplete();

    ...

    fillObject(){       
        this.opcionStyle.width=550;
        this.opcionStyle.height=150;
        this.opcionStyle.isOverflowY=true;    
        this.opcionesAutocompleteClientes.opcionStyle = this.opcionStyle; //The error is here
    }   
}

The error is present in the line:

this.opcionesAutocompleteClientes.opcionStyle = this.opcionStyle;

"Property opcionStyle does not exist in type "OpcionesAutocomplete"

Answer №1

It appears there has been a typing error on your part

this.opcionesAutocompleteClientes.opcionesStyle = this.opcionStyle;

Your class is

export class OpcionesAutocomplete implements IOpcionesAutocomplete {      
     opcionesStyle: OpcionStyle;
     opcionPropiedades: OpcionPropiedades;

     constructor()  { }
}

This class contains opcionesStyle, not opcionStyle

Answer №2

Oops, a simple typo! Let's correct it to:

this.opcionesAutocompleteClientes.opcionesStyle = this.opcionStyle;

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

Updating Firebase token in Angular when it has expired

Currently working on a website using Angular, I have integrated the Firebase SDK for email/password authentication. The main aim is to automatically generate a new token if the user closes the site and returns after a week. However, I am unsure which func ...

How can I retrieve the height of a dynamically generated div in Angular and pass it to a sibling component?

My setup consists of a single parent component and 2 child components structured as follows: Parent-component.html <child-component-1 [id]="id"></child-component-1> <child-component-2></child-component-2> The child-compo ...

Why is my custom 404 page failing to load after building my Next.js application?

I recently set up a custom 404 page for my Next.js app and wanted to test it locally before deploying to the server. To do this, I used the "serve" package to host the project on my local machine. However, when I tried navigating to a non-existent page, th ...

Sharing API Results with All Components in Angular 7 using BehaviorSubject

My goal is to optimize an API call that fetches data about the current user (such as their username, full name, group memberships, email address, and more) by ensuring it's only made once per user session and that the data is shared across all compone ...

What steps should I take to resolve an unhandled promise error in a React TypeScript application while making an axios POST request?

I am currently working on a .tsx file to implement adding an enterprise feature. Although I can input data, clicking the submit button does not trigger any action. My application includes a page that has a button for adding a new enterprise. Upon clickin ...

How to upload files using 3 input fields in Angular?

Seeking assistance on uploading 3 files using 3 different inputs. I'm a beginner in Angular, so please excuse any naive inquiries. Here is the code snippet: BookFormComponent.ts: export class BookFormComponent implements OnInit { audioFile: File ...

Angular 4 seems to be experiencing some issues with the EventEmiitter functionality

Hey everyone, I'm new to working with Angular 4 and I've been trying to implement the event emitter concept without success. Here's the code I have in my demo: app.component.ts import { Component } from '@angular/core'; @Compon ...

Tips for extracting elements from an HTML document using Angular

I seem to be facing a small issue - I am trying to develop a form using Angular. Below is my HTML: <form [formGroup]="requeteForm" (ngSubmit)="ajouter()" *ngIf=" tables!= null"> <div class="form-group&quo ...

Understanding the Typescript Type for a JSON Schema Object

When working with JSON-schema objects in typescript, is there a specific type that should be associated with them? I currently have a method within my class that validates whether its members adhere to the dynamic json schema schema. This is how I am doing ...

Issue with Angular 2 directive update detection; unresolved directive not refreshing

I have created an Angular 2 application that displays a number which can be either negative or positive. In order to change the font color to red when the value is negative, I've implemented a directive. This number gets updated constantly through an ...

Assign a specific HTML class to serve as the container within an Angular directive

Is there a way to dynamically add and set an HTML class using an Angular directive with a parameter? Let's consider a scenario where we have a div with an existing class but no directive: <div class="myClass"></div> Now, if we w ...

What is the best way to shorten text in Angular?

I am looking to display smaller text on my website. I have considered creating a custom pipe to truncate strings, but in my situation it's not applicable. Here's what I'm dealing with: <p [innerHTML]="aboutUs"></p> Due to t ...

Exploring Angular Route Configurations: Utilizing Multiple Outlets with Path as an Array of

In my Angular9 application, I have configured hundreds of routes paths. Is there a way to use multiple outlets with a single array of string paths? Current Code: const routes: Routes = [ { path: 'Data/:EntityID/:Date', compon ...

Typescript - using optional type predicates

I'm looking to create a custom type predicate function that can accurately determine if a number is real and tighten the type as well: function isRealNumber(input: number | undefined | null): input is number { return input !== undefined && ...

Angular web application can retrieve JSON data from a web API controller, allowing for

I'm currently utilizing ASP.NET Core on the backend and Angular on the frontend. My API delivers data in JSON format from the backend. I've set up a service to fetch the API data, but it's returning 'undefined' at the moment. emp ...

Unable to modify the active property of the specified object as it is read-only

Presented here is the interface: export interface ProductCommand extends ProductDetailsCommand { } This is the ProductDetailsCommand interface: export interface ProductDetailsCommand { id: string; active: boolean; archive: boolean; title: ...

What is the recommended approach for testing a different branch of a return guard using jest?

My code testing tool, Jest, is indicating that I have only covered 50% of the branches in my return statement test. How can I go about testing the alternate branches? The code snippet below defines a function called getClient. It returns a collection h ...

Issues with Angular not reflecting data changes in the view after updates have occurred

I have a setup with two components. One is responsible for creating new data entries, while the other one is in charge of listing all the data stored in a database. The issue I'm facing is that even though the creation component successfully adds new ...

Show details when clicked with various elements

I have a dilemma with my Angular version 7 project. In a div, I have placed 6 buttons in 2 columns and I want to show a description of one button only when it is clicked. Currently, the description for all buttons displays at once upon clicking any button. ...

Tips on passing an object as data through Angular router navigation:

I currently have a similar route set up: this.router.navigate(["/menu/extra-hour/extra-hours/observations/", id]) The navigation is working fine, but I would like to pass the entire data object to the screen in order to render it using the route. How can ...