我試圖繼承基本接口IScreen將IModal,IEmbedded或ITab擴展,並鎖定方法,以便它們特定於接口。但是會發生什麼是public OpenModal(modal: IModal)
方法由於某種原因接受任何類型。爲什麼一個接口參數允許任何類型
namespace Framework {
"use strict";
interface IScreen { }
interface IModal extends IScreen { }
interface ITab extends IScreen { }
interface IEmbedded extends IScreen { }
class BaseScreen implements IScreen {
public HandleCloseEvent() {
}
}
class DetailsScreen extends BaseScreen implements IModal {
}
class ListScreen extends BaseScreen implements IEmbedded {
}
class OpenerService {
public OpenScreen(screen: IScreen) {
}
public OpenModal(modal: IModal) {
}
}
class Controller {
constructor(openerService: OpenerService) {
var detailsScreen: DetailsScreen = new DetailsScreen();
var listScreen: ListScreen = new ListScreen();
openerService.OpenModal(212121); // Expected error
openerService.OpenModal(listScreen); // Expected error
}
}
}
- 我失去了,我沒有收到 任何錯誤,一些編譯器配置?
- 我誤解了界面是如何工作的?
我相信這是因爲你的接口是空的;它應該在你添加屬性時改變。 –