2017-11-25 9 views
1

のマージ、私は言及していたプロジェクトはここにある:https://github.com/abauzac/nightwatch-typescriptは、問題を暴露する前にtypescriptです外部グローバルインターフェイスと継承

私の問題は、ナイトウォッチの定義である、それは(ない名前空間内のグローバルインタフェースの多くをエクスポートしたり、

./node_modules/@types/nightwatch:含むモジュールhttps://github.com/DefinitelyTyped/DefinitelyTyped/blob/38bd4efd5dc8c666f70d77b020a0b64a13ce3980/types/nightwatch/index.d.ts)、ナイトウォッチへ

export interface NightwatchCustomCommands { /* empty interface */ } 
export interface NightwatchCustomAssertions { /* empty interface */ } 

export interface NightwatchBrowser extends NightwatchCustomCommands, NightwatchCustomAssertions, ... { ... } 

export interface NightwatchAssertions extends NightwatchBrowser { ... } 

私が追加したカスタムコマンドとアサーションとは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"これまでのところ、インターフェイスに "エクスポート"を追加しようとしましたが、名前空間には何が欠けているのか分かりません。

+0

私は実際には問題の一部であり、どのようなコード言うことができないあなたがしようとしたものが何であると捨てられました。あなたが試みているコードだけを表示すると、私は助けることができます。たとえば、2番目のコードブロックでは、継承を行っていないので、私はあなたの意図が何であるかを知ることができません。 –

+0

私がしようとしているのは、ここの2番目のセクションで説明したようなインターフェースをマージすることです:https://www.typescriptlang.org/docs/handbook/declaration-merging.html。継承されたインターフェイス(最初のブロック)で考慮する私のインターフェイス(2番目のブロック)を参照することを期待しています – bqlou

答えて

1

は、私はこれをチェックしていないが、私は、モジュールの宣言であること取り囲むようにあると思う:

import * as NW from "nightwatch"; 

    declare module "nightwatch" { 
    export interface NightwatchCustomAssertions { 
     compareScreenshot(this: NW.NightwatchBrowser, filename: string, expected: number, callback: Function): any; 
    } 

    export interface NightwatchCustomCommands { 
     wplogin(this: NW.NightwatchBrowser, callback?: Function):this; 
     compareScreenshot(this: NW.NightwatchBrowser, filename: string, expected?: number, callback?: Function): any; 
    } 
    } 
+0

まだ正確に同じエラーを取得...しかし、私はこの1つを試していない。 – bqlou

+0

@bqlou修正されました。そのコードを '.d.ts'ファイルに入れるべきです。 – lilezek

+0

ありがとう、解決済みとマークされています:) – bqlou