@types/nightmare package and had problems.Definitions by: in index.d.ts) so they can respond.Taken straight from Nightmare's .evalute() example usage:
const selector = 'h1'
nightmare
.evaluate((selector: string) => {
// now we're executing inside the browser scope.
return (document.querySelector(selector) as HTMLHeadingElement).innerText
}, selector) // <-- that's how you pass parameters from Node scope to browser scope
.then(text => {
// ...
})
I am getting this compile error.
error TS2345: Argument of type '(selector: string) => string' is not assignable to parameter of type '() => string'.
@horiuchi, @samyang-au, @Bleser92, any updates on the issue?
@piousdeer I am also running into the same problem. Did you ever find a solution to this?
@JamesRArroyo unfortunately not. I had to uninstall @types/nightmare completely.
I've hit the same issue. The problem is that the type definitions are for Nightmare v2, while the current version is v3. The evaluate signature has changed since v2 - a mandatory callback argument has been removed. This is why TypeScript will not be able to work with this package until it it properly rewritten for v3.
As a temporary measure, I modified the typings, index.d.ts, lines 38-43:
evaluate<T1, T2, T3, R>(fn: (arg1: T1, arg2: T2, arg3: T3) => R, arg1: T1, arg2: T2, arg3: T3): Nightmare;
evaluate<T1, T2, R>(fn: (arg1: T1, arg2: T2) => R, arg1: T1, arg2: T2): Nightmare;
evaluate<T, R>(fn: (arg: T) => R, arg: T): Nightmare;
evaluate<T>(fn: (arg: T) => void, arg: T): Nightmare;
evaluate<R>(fn: () => R): Nightmare;
evaluate(fn: () => void): Nightmare;
So now I can write something like this:
import * as Nightmare from "Nightmare";
const nightmare = new Nightmare({
show: true
});
const input: number = 0;
(async () => {
await nightmare.goto("https://github.com/")
.wait("h1")
.evaluate<number, string>( // number = argument type, string = output type
(_input: number) => {
const title: any = document.querySelectorAll("h1");
return title[_input].textContent as string;
},
input
)
.end()
.then((result: string) => {
console.log(result);
});
})();
@horiuchi @samyang-au @Bleser92 Can we expect typings for Nightmare v3 anytime soon?
Most helpful comment
I've hit the same issue. The problem is that the type definitions are for Nightmare v2, while the current version is v3. The
evaluatesignature has changed since v2 - a mandatory callback argument has been removed. This is why TypeScript will not be able to work with this package until it it properly rewritten for v3.As a temporary measure, I modified the typings, index.d.ts, lines 38-43:
So now I can write something like this:
@horiuchi @samyang-au @Bleser92 Can we expect typings for Nightmare v3 anytime soon?