【发布时间】:2019-07-20 01:58:28
【问题描述】:
我知道有很多与此问题相关的问题/答案,据我所知,我了解它的性质,但我不明白为什么它会发生在我明确设置和控制的类型上。
我特意在tsconfig.json 中将noImplicitAny 设置为true;我知道如果我把它转到false,这个问题就会消失——但我不想那样做......但是:)
这是代码:
# ./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);
});
});
...最后,我的tsconfig.json(位于项目的根目录):
{
"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/**/*"]
}
使用该设置,我总是收到相同的错误消息:
[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
【问题讨论】:
-
即使错误指向我可以看到的类,该类也没有问题
-
是的,这里也一样。这个错误对我来说毫无意义,但一定有什么……
-
你的IDE中的文件有错误吗?因为我怀疑它与您的测试如何编译这些文件有关;如果 IDE 中没有错误,那么无论您的测试通过什么管道运行这些文件,这都是编译问题
标签: typescript typescript-typings webdriver-io