简体   繁体   English

类型缺少类型的以下属性?

[英]Type is missing the following properties from type?

I got this message 我收到了这条消息

Class 'Motorvoertuig' incorrectly implements interface 'Voertuig'. 类'Motorvoertuig'错误地实现了接口'Voertuig'。
Type 'Motorvoertuig' is missing the following properties from type 'Voertuig': toonMerk, wieIsDeEigenaar 类型'Motorvoertuig'缺少类型'Voertuig'的以下属性:toonMerk,wieIsDeEigenaar

But I really don't know why? 但我真的不知道为什么?

I have more code in this document but the error comes from the following Methodes. 我在本文档中有更多代码,但错误来自以下Methodes。

interface Voertuig {
     merk: string;
    eigenaar: string;

    toonMerk(merk:string);
    wieIsDeEigenaar(eigenaar:string);
};
abstract class Motorvoertuig implements Voertuig {
  (Some code)
}

How to get rid of this error? 如何摆脱这个错误?

You have marked Motorvoertuig as implementing Voertuig interface that means you need to add all fields present in Voertuig interface to Motorvoertuig class. 您已将Motorvoertuig标记为实现Voertuig接口,这意味着您需要将Voertuig接口中存在的所有字段添加到Motorvoertuig类。 So for example: 例如:

abstract class Motorvoertuig implements Voertuig {
  merk: string = '';
  eigenaar: string = '';
  toonMerk(merk: string) {}
  wieIsDeEigenaar(eigenaar: string) {}
}

or you can try using something like: 或者您可以尝试使用以下内容:

abstract class Motorvoertuig implements Partial<Voertuig> {
}

check advanced typescript types 检查高级打字稿类型

When you implement an interface, you need to define the properties that are declared in the interface. 实现接口时,需要定义接口中声明的属性。 In Motorvoertuig , you probably have defined merk and eigenaar , but not toonMerk and wieIsDeEigenaar . Motorvoertuig ,你可能已经定义了merkeigenaar ,但不是toonMerkwieIsDeEigenaar

If you don't want to implement those methods inside your abstract class Motorvoertuig , you can make the methods abstract like this: 如果您不想在抽象类Motorvoertuig实现这些方法,可以使方法像这样抽象:

abstract toonMerk(merk: string);
abstract wieIsDeEigenaar(merk: string);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型“{}”缺少类型“IResponseConfig”中的以下属性 - Type '{}' is missing the following properties from type 'IResponseConfig' 错误:类型“{}”缺少类型中的以下属性 - Error: Type '{}' is missing the following properties from type 类型“文档”缺少类型中的以下属性 - Type 'Document' is missing the following properties from type “EventTarget”类型缺少以下属性 - Missing the following properties from type 'EventTarget' Typescript Angular - 接收类型缺少以下类型的属性 - Typescript Angular - Recieving Type is missing following properties from type TS 错误:“事件”类型缺少“键盘事件”类型中的以下属性 - TS error: Type 'event' is missing the following properties from type 'keyboardevent' 类型 A 缺少类型 B 的以下属性:a、b - Type A is missing the following properties from type B: a, b 错误 TS2739:类型“{}”缺少类型中的以下属性 - error TS2739: Type '{}' is missing the following properties from type 类型“订阅”缺少类型“可观察”的以下属性 <StringMap<any> &gt;” - Type 'Subscription' is missing the following properties from type 'Observable<StringMap<any>>' Typescript - X 型缺少 X 型的以下属性 - Typescript - Type X is missing the following properties from type X
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM