Are the missing attributes the type of properties that are absent?

I have a pair of interfaces:

meal-component.ts:

    export interface MealComponent {
    componentId: string;
    componentQuantity: number;
}

meal.ts:

import { MealComponent } from 'src/app/interfaces/meal-component';

export interface Meal {
    name: string;
    components: MealComponent[];
    totalCost: number;
}

Working within Angular, in my meal component I am attempting to create a new Meal:

meals.component.ts:

import { Component } from '@angular/core';
import { Meal } from 'src/app/interfaces/meal';
// other imports

@Component({
  selector: 'app-meals',
  templateUrl: './meals.component.html',
  styleUrls: ['./meals.component.css']
})

export class MealsComponent {

  // other elements

  myMeal: Meal = {
    name: "myTestMeal",
    components: [
      {
        componentId: "sdfhsd6786sdf",
        componentQuantity: 5,
      },

      {
        componentId: "jhk87sjk98shj",
        componentQuantity: 7,
      },
    ],
    totalCost: 3872,
  };

  // other elements
}

myMeal triggers the error:

Type '{ name: string; components: { componentId: string; componentQuantity: number; }[]; totalCost: number; }' is missing the following properties from type 'Meal': componentId, componentQuantity ts(2739)

I'm confused, how are the properties componentId and componentQuantity missing? What could be the issue here?

It's possible that there might be something simple that I'm overlooking, so any assistance is appreciated.

Solution:

Remove the extends statement in meal.ts. The Meal extending MealComponent implies it needs to contain all the properties of MealComponent.

Answer №1

When you eliminate the "extends" keyword from your code, you will notice that everything functions correctly. DishComponent specifically needs cmpId and cmpQt to be set, which is not currently being done. You must either provide values for these properties or remove them altogether - the latter option is likely the solution.

The "extends" keyword essentially duplicates the attributes of the interface it references.

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

Challenges arise when trying to access environment variables using react-native-dotenv in React

I am currently working on two separate projects, one being an app and the other a webapp. The app project is already set up with react-native-dotenv and is functioning as expected. However, when I attempt to use the same code for the webapp, I encounter an ...

Experience the power of Stimulsoft reporting integrated with Angular and Asp.net Core-framework!

I've created a Webservice in Asp.net Core to generate reports which is then called in an Angular app to display the reports. However, when I try to show the report in Angular, it only shows a blank page. What could be causing this issue and how can I ...

Unable to apply the CSS styles on the webpage

I'm having trouble adjusting the CSS for a specific div with the class .cropper inside a component named image-cropper, and I can't figure out why it's not taking effect. Here is an image of the particular div. Below is the CSS code I atte ...

Having trouble with customizing a selected ListItemButton in Material-UI - need some help with

After reviewing the documentation, I discovered a method to override the styling of the selected class by introducing a new class under .MuiSelected. The implementation looks something like this: const customStyles = makeStyles(() => ({ customizedSele ...

Jest test encounters Firebase initialization error

Testing event handlers for a slack bolt app has been quite the rollercoaster. Initially, all tests passed flawlessly, making life wonderful. However, after some refactoring, the entire test suite failed to run, displaying an error indicating that firebase ...

What is the best way to extract a variable from a URL and assign it to an Ionic variable

I am currently developing a project in Ionic 3 that utilizes the admob plugin. I have set up two variables (Mybanner and Myinterstital) to store the admob code, and I would like to retrieve the content of these variables from an external URL like this: ht ...

Angular 5 - Strategies for excluding specific properties from Observable updates

Currently, I am in the process of developing a webpage where users can view and like various videos. The video content and user likes are stored in a database, and I have implemented two Angular services for handling data retrieval and storage. However, I ...

Unusual actions observed in Ionic 3 app using webview 3 plugin

I am currently facing a significant problem with Webview 3. One of our developers upgraded it to webview 3 without utilizing the Ionic native webview plugin, and surprisingly, it is functioning well on our Ionic 3 application. As per the documentation avai ...

Is there a way to keep this table fixed in place as the user scrolls?

Is there an alternative way to fix the content on the header so that it remains visible on the screen until the next table, even when scrolling? I've tried using position: sticky and top: 0, but the header still scrolls past. I have checked for any ov ...

Will adding additional line breaks increase the overall length of the code?

Currently, I am immersed in a project involving Angular 4 and TypeScript. Recently, I came across a video showcasing how VSCODE can enhance the code's appearance. Intrigued, I installed the prettier plugin to achieve the same effect. Running this tool ...

Mapping a Tuple to a different Tuple type in Typescript 3.0: Step-by-step guide

I am working with a tuple of Maybe types: class Maybe<T>{ } type MaybeTuple = [Maybe<string>, Maybe<number>, Maybe<boolean>]; and my goal is to convert this into a tuple of actual types: type TupleIWant = [string, number, boolea ...

How to delay setting a property in Angular 2 until the previous setter has finished execution

Hey there, I'm facing an issue with my component. Within my component, I have an input setter set up like this: @Input() set editStatus(status: boolean) { this.savedEditStatus = status; if (this.savedEditStatus === true && this.getTrigg === t ...

Resetting the modal scroll time when the content of the modal is refreshed

I have implemented the modal in my application using ng-bootstrap. Within the modal, there are multiple pages that can be navigated using the Next and Back buttons. An issue I am facing is that when a page is long and requires scrolling, it loads in the ...

Issue with Ng test: The type definition file for '@angular/localize' cannot be located

When upgrading from Angular 14 to 17, I ran into an issue with the ng test command. It seems to be malfunctioning now. Error: PS C:\ForAngular17\src\ng\cat-ng> ng test One or more browsers configured in the project's Browsersli ...

Utilizing a personalized component with a mat-autocomplete feature within reactive forms by nesting

I'm struggling to add a nested component to the parent form group when the component only contains a mat-autocomplete. I attempted the same method used for the address subform which worked well, but for the user search, it's required to pass in t ...

Challenges arise when dealing with generics in TypeScript

I'm a beginner in TypeScript and I'm trying to write a method with a generic type argument similar to what you can do in .Net. Here's the code snippet I've been working on: class TestObject { Id: number; Truc: string; Machin: str ...

Leverage the power of forkJoin alongside activatedRoute

One of the observables I'm working with is the following: formData$ = forkJoin([ this.httpService.getProgramsLevelsList(), this.httpService.getProgramsTypesList(), this.httpService.getQuestionnaireReasonsList() ]).pipe( tap((res: any) => ...

What is the best way to send parameters to an async validator when working with reactive controls in Angular

Issue with Validation I am facing a challenge while using the same component for both read and edit routines. The async-validator functions perfectly when dealing with new entries. However, a problem arises if the user mistakenly changes a value and then ...

Steps for converting TypeScript code to JavaScript using jQuery, without the need for extra libraries or frameworks like NPM

My single-page dashboard is quite basic, as it just displays weather updates and subway alerts. I usually refresh it on my local machine, and the structure looked like this: project/ index.html jquery-3.3.1.min.js script.js I decided to switch it t ...

Establishing the starting value for Angular 2's reactive FormArray

I am having trouble setting the initial value for an angular 2 reactive form formArray object. Despite using a json object with multiple entries to set the form value, only the first entry is displayed and "form.value" also only shows the first entry. To ...