如何使用WebStorm以TypeScript而不是JavaScript创建Cucumber步骤定义文件?

如何使用WebStorm以TypeScript而不是JavaScript创建Cucumber步骤定义文件?,javascript,typescript,cucumber,webstorm,cucumberjs,Javascript,Typescript,Cucumber,Webstorm,Cucumberjs,我正在使用Cucumber.js构建一个新的e2e测试套件,我想对我的step文件使用TypeScript。当我创建一个新步骤并按下Alt+Enter让WebStorm生成一个新步骤文件时,我看到的唯一选项是创建一个JavaScript文件 有人知道如何在TypeScript中创建新的步骤文件吗?Webstorm似乎没有为文件类型“TypeScript”提供向导,因此您可能需要手动创建步骤定义文件 对于可能的TS步骤定义文件,可能如下所示: import * as cucumber from "

我正在使用Cucumber.js构建一个新的e2e测试套件,我想对我的step文件使用TypeScript。当我创建一个新步骤并按下
Alt+Enter
让WebStorm生成一个新步骤文件时,我看到的唯一选项是创建一个JavaScript文件


有人知道如何在TypeScript中创建新的步骤文件吗?

Webstorm似乎没有为文件类型“TypeScript”提供向导,因此您可能需要手动创建步骤定义文件

对于可能的TS步骤定义文件,可能如下所示:

import * as cucumber from "cucumber";

module.exports = function () {
    // Assign this to a typed variable so we have type-safe access
    let sd: cucumber.StepDefinitions = this;

    // The common variable is simply kept in function scope here
    let variable: number = 0;

    sd.Given(/^a variable set to (\d+)$/, (value: string) => {
        variable = parseInt(value);
    });

    sd.When(/^I increment the variable by (\d+)$/, (value: string) => {
        variable += parseInt(value);
    });

    sd.Then(/^the variable should contain (\d+)$/, (value: string) => {
        if (variable != parseInt(value))
            throw new Error('Variable should contain '+value
                          + ' but it contains ' + variable + '.');
    });
};

将此内容放入features/step_definitions/mathSteps.ts中,并将功能代码从粘贴到一个名为features/math.feature的文件中,您应该有一个运行示例。

我选择此答案只是因为
Webstorm似乎没有为文件类型“TypeScript”提供向导。
部分。这正是我想知道的。谢谢我无法通过cucumber.StepDefinitions访问任何内容。错误:
StepDefinitions
在类型“typeof path/to/my/cucumber/@types/index.ts”上不存在