之前暴露的問題,我指該項目是在這裏:https://github.com/abauzac/nightwatch-typescript合併打字稿外部全局接口和繼承
我的問題是夜巡定義,它在全球(不出口了大量的接口,在命名空間裏或模塊https://github.com/DefinitelyTyped/DefinitelyTyped/blob/38bd4efd5dc8c666f70d77b020a0b64a13ce3980/types/nightwatch/index.d.ts),包括:
./node_modules/@types/nightwatch:
export interface NightwatchCustomCommands { /* empty interface */ }
export interface NightwatchCustomAssertions { /* empty interface */ }
export interface NightwatchBrowser extends NightwatchCustomCommands, NightwatchCustomAssertions, ... { ... }
export interface NightwatchAssertions extends NightwatchBrowser { ... }
我已經添加自定義命令和斷言Nightwatch並試圖合併NightwatchCustomCommands和NightwatchCustomAssertions:
./types/index.d.ts
import { NightwatchAssertions, NightwatchBrowser } from "nightwatch";
// merge interfaces with nightwatch types
interface NightwatchCustomAssertions {
compareScreenshot(this: NightwatchBrowser, filename: string, expected: number, callback: Function);
}
interface NightwatchCustomCommands {
wplogin(this: NightwatchBrowser, callback?: Function):this;
compareScreenshot(this: NightwatchBrowser, filename: string, expected?: number, callback?: Function)
}
但它似乎編譯時接口不被合併:
Property 'wplogin' does not exist on type 'NightwatchBrowser'.
Property 'compareScreenshot' does not exist on type 'NightwatchAssertions'.
兩個@types和類型的文件夾都包含在tsconfig 「typeRoots」。到目前爲止,我嘗試添加「導出」到接口,命名空間......不知道我錯過了什麼。
我不能告訴實際上是什麼代碼問題的一部分,什麼是你嘗試過的東西和被遺棄。如果您只顯示您正在嘗試的代碼,我可以提供幫助。例如,在第二個代碼塊中,你甚至沒有做任何繼承,所以我不知道你的意圖是什麼。 – 2017-11-25 23:25:24
我正在嘗試合併接口,如第二部分所述:https://www.typescriptlang.org/docs/handbook/declaration-merging.html。我期待看到我的接口(第二塊)在繼承的接口(第一塊)中被考慮到 – bqlou