Reputation: 3586
In my Angular CLI v7.3.6 project, I have a protractor.conf.js
file. I'd like to enable @ts-check
in this file in my VSCode. When @ts-check
is eanbled, I'd like to call browser.getCapabilities()
in the onPrepare()
callback but VSCode said Unable to find name 'browser'. ts(2304)
.
The browser should be registered into Global
. I tried to use <reference path="..."/>
syntax, but no browser
has been declared.
/// <reference path="../node_modules/protractor/built/index.d.ts" />
I can't figure out how to declare Global properties with type in a js file (Node.js).
How can I declare browser
's type in protractor.conf.js
file?
Upvotes: 1
Views: 470
Reputation: 3586
I finally figure out the solution:
Add the following comment at first line of the protractor.conf.js
.
// @ts-check
Add the following local variable and get real value from global, then assign typing to this local variable.
/**
* @type { import("protractor").ProtractorBrowser }
*/
let browser = global['browser'];
Here is the screenshot of the usage:
Upvotes: 2