TypeScript – “Prototype” in the “MyObject” type

I want to use Angular2 to write a web application on Webstorm. I am very good at doing this. I am trying out the tutorial on the angular website Angular.IO.

< p>When I try to list the clickable list of Person, it doesn’t work.

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 received the following error:

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

What does this mean? I can’t find this error on the Internet. Due to my lack of experience, this may be anything I can’t see on the code

When you write:

selectedPersons = Person;

You are assigning the variable selectedPersons to the class Person Reference to the default value. What you might intend to do is to specify that the selectedPersons class attribute will contain instances of the Person class. You can do this:

selectedPersons:Person;

I want to use Angular2 to write a web application on Webstorm. I am very good at doing this. I am trying out the tutorial on the angular website Angular.IO.

When I try to list the clickable list of Person, it doesn’t work.

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}
];< br />
export class Person {
id: number;
firstName: string;
lastName: string;
creationData: any;
}

I received the following error:

< blockquote>

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

What does this mean? I can’t find this error on the internet. Due to my lack of experience, this may be anything I can’t see on the code

When you do Write:

selectedPersons = Person;

You are assigning the variable selectedPersons the default value of the class Person reference. What you might intend to do is specify The selectedPersons class attribute will contain instances of the Person class. You can do this:

selectedPersons:Person;

Leave a Comment

Your email address will not be published.