赛普拉斯测试无法识别node_modules封装类型

时间:2020-09-04 14:16:16

标签: javascript typescript cypress tsconfig

我的(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的类型在DefinitelyTypes(@types/faker)中定义,而utility-types的类型作为*.d.ts文件包含在该包中。 faker导入没有问题,但是utility-types导入给出了找不到模块'实用程序类型'或其对应的类型声明。错误。

我已经尝试将*.d.ts文件从node_modules目录显式地包含到tsconfig.jsoncompilerOptions.typescompilerOptions.typeRoots属性下的include文件中,但是无济于事。

我还创建了如下的“假”(?)类型,以便进行编译:

declare module 'utility-types' {
  export type DeepPartial<T> = {};
}

这允许应用程序进行编译,并且在运行时解决了程序包,因此问题似乎在于查找类型,而不是模块本身。

为什么赛普拉斯没有找到这些软件包的类型?

1 个答案:

答案 0 :(得分:2)

您可以尝试将cur.execute("select format('%s, %s, %s', 'one', 'two', 'three') from foo where bar = %s", ('baz',)) 设置为moduleResolution

https://www.typescriptlang.org/docs/handbook/module-resolution.html#module-resolution-strategies

我尝试使用此配置导入node:导入有效,并且测试运行正常

utility-types