Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property 'prototype' is missing in type 'MyObject'

Tags:

typescript

I want to write a web-application on Webstorm with Angular2. I am very new on do this. I am trying the tutorial on the angular website Angular.IO.

When I try to make a list of Person clickable, it is not working.

export class PersonComponent {
 persons = MYPERSONS;
 selectedPersons = Person;

 onSelect(person: Person): void {
  this.selectedPerson = person;   // here is the error on "this.selectedPerson"
 }
}

const MYPERSONS: Person[] = [
 {id:0, firstName: 'First', lastName: 'Firstly', creationData: 1},
 {id:1, firstName: 'Second', lastName: 'Test', creationData:10},
 {id:2, firstName: 'Third', lastName: 'Candidate', creationData:5}
];

export class Person {
 id: number;
 firstName: string;
 lastName: string;
 creationData: any;
}

I get the following error:

Type 'Person' is not assignable to type 'typeof Person'. Property 'prototype' is missing in type 'Person'.

What does it mean? I can't find this error on the internet. It is probably anything what I'm not seeing on the code because of my few experience

like image 248
TYL Avatar asked Aug 28 '17 13:08

TYL


1 Answers

When you write like this:

selectedPersons = Person;

you're assigning a default value of a class Person reference to the variable selectedPersons. What you're probably intending to do is to specify that selectedPersons class property will hold a Person class instance. You can do it like this:

selectedPersons:Person;
like image 140
Max Koretskyi Avatar answered Nov 14 '22 08:11

Max Koretskyi