【发布时间】:2020-12-23 19:54:09
【问题描述】:
我的 (Typescript) 应用程序的赛普拉斯测试识别我已安装的包的类型时遇到问题。这是我的顶级目录结构:
cypress
node_modules
src
我的cypress/tsconfig.json 文件如下所示:
{
"compilerOptions": {
"strict": true,
"baseUrl": "../node_modules",
"paths": {
"~/*": ["../src/*"]
},
"jsx": "react",
"target": "es6",
"lib": ["es6", "dom", "es2017.string"],
"types": ["cypress"]
},
"include": ["**/*.ts"]
}
在我的一个规范文件中,我有以下导入:
import * as faker from 'faker';
import { DeepPartial } from 'utility-types';
faker 的类型在 DefinedlyTypes (@types/faker) 中定义,而 utility-types 的类型作为 *.d.ts 文件包含在该包中。 faker 导入没有问题,但 utility-types 导入给出了 Cannot find module 'utility-types' 或其对应的类型声明。错误。
我已尝试将 node_modules 目录中的 *.d.ts 文件显式包含到 compilerOptions.types、compilerOptions.typeRoots 和 include 属性下的 tsconfig.json 文件中,但无济于事。
我还创建了如下所示的“假”(?) 类型,因此它可以编译:
declare module 'utility-types' {
export type DeepPartial<T> = {};
}
这允许应用编译并在运行时解析包,因此问题似乎在于查找类型,而不是模块本身。
为什么赛普拉斯没有找到这些包的类型?
【问题讨论】:
-
尝试将以下内容添加到您的
.tsconfig:"include": [ "node_modules/cypress/types/index.d.ts", "node_modules/cypress/types/blob-util.d.ts", "node_modules/cypress/types/minimatch.d.ts", "node_modules/cypress/types/bluebird.d.ts", "cypress/**/*.ts" ] -
作为参考,我查看了一个带有工作 TS 环境的示例 repo:github.com/cypress-io/cypress-example-recipes/blob/master/…
-
@RaghavKukreti 我应该提到除了
types和typeRoots之外,我还尝试了includetsconfig 属性。它不起作用。
标签: javascript typescript cypress tsconfig