Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

150
Views
Angular Object literal may only specify know properties and ... does not exist in type

I'm starting out with Angular and running into an error.

.../mocks.ts(9,4): Type '{"id": number; "name": string; "description": string; "inStock": number; "price": number; "featu...' is not assignable to type 'CarPart[]. Object literal may only specify known properties, and '"featured"' does not exist in type 'CarPart'.

My code:

car-part.ts

export class CarPart {
    id: number;
    name: string;
    description: string;
    inStock: number;
    price: number;
    featured: boolean;
}

mock.ts

import { CarPart } from './car-part';

export const CARPARTS: CarPart[] = [{
    "id": 1,
    "name": "Super Tires",
    "description": "These tires are the very best",
    "inStock": 5,
    "price": 299.99,
    "featured": false //Line 9
  }, 
  {
    "id": 2,
    "name": "Reinforced Shocks",
    "description": "Shocks made of kryptonite",
    "inStock": 4,
    "price": 500.50,
    "featured": false
  },
  {
    "id": 3,
    "name": "Padded Seats",
    "description": "Super soft seats for a smooth ride",
    "inStock": 0,
    "price": 333.33,
    "featured": true
  }];

car-parts.component.ts

import { Component, OnInit } from '@angular/core';
import { CarPart } from './car-part';
import { CARPARTS } from './mock';

@Component({
  selector: 'car-parts',
  templateUrl: './car-parts.component.html',
  styleUrls: ['./car-parts.component.css']
})
export class CarPartsComponent implements OnInit {

  constructor() { }

  carParts: CarPart[];

  totalCarParts(){
    let sum = 0;

    for(let carPart of this.carParts){
        sum += carPart.inStock;
    }
    return sum;
  }

  ngOnInit() {
    this.carParts = CARPARTS;
  }

}

when I remove "featured" from both mock.ts and car-part.ts it is fine, no error. If I add it or any other name or type, it wont work... Can someone explain this?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I restarted the Angular CLI server (Ctrl+C > ng serve). Compiled without problems...

Evidence that "Have you tried turning it off and on again" is still relevant. Thanks for the time looking at the problems Tim and Max

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!