lea*_*mer 7 interface class typescript
我在界面上有这个字段:
// Stores the to views folder
VIEW_PATH: string;
// Stores BrowserWindows with respective view
browserWindows: [string, BrowserWindow | null][];
Run Code Online (Sandbox Code Playgroud)
当我在类中实现这些字段并尝试将它们设置为私有时,出现以下错误:
Class 'WindowHandler' incorrectly implements interface 'IWindowHandler'.
Property 'VIEW_PATH' is private in type 'WindowHandler' but not in type 'IWindowHandler'.ts(2420)
Run Code Online (Sandbox Code Playgroud)
当我尝试将接口字段设置为私有时:
'private' modifier cannot appear on a type member.ts(1070)
Run Code Online (Sandbox Code Playgroud)
接口本质上是公共的,因此只能有公共成员,因此它们不接受私有/受保护等定义。另一方面,接口(例如类)的实现可以具有其实现细节的私有成员/方法。
您可能误解了接口的概念,接口是您与公共世界之间的一种“契约”,因此这些契约中没有逻辑使用“隐藏”元素,或者您试图以不正确的方式使用它们方式。让我知道您的用例是什么,以及为什么您希望某些成员保密,以便进一步帮助您。
| 归档时间: |
|
| 查看次数: |
3470 次 |
| 最近记录: |