I know there are tons of questions/answers related with this issue, and as far as I can tell, I understand the nature of it, but I can't understand why would it happen on types I explicitly set and control.
I have purposely set noImplicitAny
to true
inside tsconfig.json
; I know that if I turn it to false
this issue will go away – but I don't want to do that...yet :)
This is the code:
# ./src/page/base.page.ts
export default class BasePage {
public open(path: string) {
browser.url(path);
}
}
# ./src/page/home-search.page.ts
import BasePage from "./base.page";
class HomeSearchPage extends BasePage {
public fillForm(term: string) {
$("#search_form_input_homepage").setValue(term);
}
public open() {
super.open(`${browser.options.baseUrl}`);
}
public submit() {
$("#search_button_homepage").click();
}
}
export default new HomeSearchPage();
# ./test/spec/search.engine.spec.ts
import HomeSearchPage from "@page/home-search.page";
import { expect } from "chai";
describe("DuckDuckGo (DDG) Search Engine", () => {
it("Verify search result(s) for given term", () => {
const expected: string = "WebdriverIO · Next-gen WebDriver test framework for Node.js";
const input: string = "webdriverio";
HomeSearchPage.open();
HomeSearchPage.fillForm(input);
HomeSearchPage.submit();
expect($("div#r1-0 h2.result__title a.result__a").getText()).to.contain(expected);
});
});
...and finally, my tsconfig.json
(located at project's root):
{
"compilerOptions": {
"alwaysStrict": true,
"baseUrl": ".",
"module": "commonjs",
"paths": {
"*": ["./*"],
"@page/*": ["./src/page/*"]
},
"removeComments": true,
"strict": true,
"target": "es2018",
"types": [
"@wdio/mocha-framework",
"@wdio/sync",
"@types/chai",
"@types/mocha",
"node"
],
//---------------------------------------------------------------------------------------------
// Experimental Settings
//---------------------------------------------------------------------------------------------
"noImplicitAny": true
},
"exclude": ["node_modules/"],
"include": ["./src/**/*", "./test/**/*"]
}
With that setup, I'm always getting the same error message:
[0-0] RUNNING in chrome - /test/spec/search.engine.spec.ts
0-0 worker error { name: 'TSError',
message:
'⨯ Unable to compile TypeScript:\nsrc/page/home-search.page.ts(5,14): error TS7006: Parameter \'term\' implicitly has an \'any\' type.\n',
stack:
'TSError: ⨯ Unable to compile TypeScript:\nsrc/page/home-search.page.ts(5,14): error TS7006: Parameter \'term\' implicitly has an \'any\' type.\n\n at createTSError
...
at Module.load (internal/modules/cjs/loader.js:653:32)' }
[0-0] FAILED in chrome - /test/spec/search.engine.spec.ts
This error is coming from ts-node
. In your wdio.conf.js
, change your before: function()
to this:
before: function (capabilities, specs) {
require("ts-node").register({ files: true, transpileOnly: true });
},
This question here also mentioned a very similar issue to what you were experiencing. I pulled your repo down locally and got the test to run successfully.