typescript “MyObject”类型中缺少属性“prototype”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45919800/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Property 'prototype' is missing in type 'MyObject'
提问by TYL
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.
我想用 Angular2 在 Webstorm 上编写一个 Web 应用程序。我对此很陌生。我正在尝试Angular网站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'.
类型 'Person' 不能分配给类型 'typeof 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
这是什么意思?我在互联网上找不到这个错误。由于我的经验很少,这可能是我在代码中没有看到的任何内容
回答by Max Koretskyi
When you write like this:
当你这样写时:
selectedPersons = Person;
you're assigning a default value of a class Person referenceto 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:
您正在为变量分配类 Person引用的默认值selectedPersons
。您可能打算做的是指定selectedPersons
类属性将保存 Person
类实例。你可以这样做:
selectedPersons:Person;