Extending certain .d.ts definitions
I am trying to use nightmare in typescript with types from DefinitelyTyped. however, the types are incomplete there (method is missing then
) and I also want to add some methods dynamically (as is done in this plugin ).
I don't understand how to extend the Nightmare interface without overlaying Definitely. I read several pages about this question:
Extend the interface defined in the .d.ts file
http://obaidurrehman.github.io/2015/10/30/extending-typeScript-definitions/
So, I tried to create a file extendNightmare.d.ts
that I placed in all other files .ts
.
declare namespace Nightmare {
class Nightmare {
waitForDevTools(): void;
then(): Nightmare;
}
}
At this point, I don't know what to do to tell the compiler to use my new definition, which should extend the existing one.
I tried adding this line to the top of the file using nightmare, but it didn't work:
/// <reference path="./extendNightmare.d.ts"/>
Also I would like to extend the interface IConstructorOptions
from the namespace Nightmare
, but I don't know how. Is it correct?
declare namespace Nightmare {
class Nightmare {
waitForDevTools(): void;
then(): Nightmare;
}
export interface IConstructorOptions {
switches: any;
}
}
The code I'm using to reproduce this issue:
/// <reference path="./extendNightmare.d.ts"/>
import * as Nightmare from "nightmare";
const switches = {
"ignore-certificate-errors": true,
"proxy-server": "localhost:10000",
};
function render_page(url) {
const options = {
switches,
};
const nightmare = new Nightmare(options);
nightmare
.goto(url)
.then((infos) => {
console.info(infos);
})
.end()
.then(() => {
console.info(`${url}: done`);
});
}
render_page("https://google.com");
In mine package.json
I have:
"nightmare": "^2.9.1",
"@types/nightmare": "^1.6.30",
source to share
No one has answered this question yet
See similar questions:
or similar: