小编Pro*_*ard的帖子

Typescript 没有选择 Jest 类型

问题

我正在尝试用笑话设置一个打字稿项目。然而,打字稿似乎没有从 中获取笑话类型@types/jest,这突出显示了我的关键字,给了我以下错误:

Cannot find name 'test'. Do you need to install type definitions for a test runner? Try 'npm i @types/jest' or 'npm i @types/mocha'. ts(2582)

在此输入图像描述

笔记:

  • 我正在使用 VS 代码
  • 我已经安装了@types/jest
  • 我尝试重新安装所有软件包
  • 我已经重新加载了我的编辑器
  • 这是我的 tsconfig.json
{
  "compilerOptions": {
    "types": ["jest", "node"]
  },
  "types": ["jest"],
  "typeRoots": ["./src/types", "./node_modules/@types"],
}
Run Code Online (Sandbox Code Playgroud)
  • 这是我的 jest.config.js
module.exports = {
  preset: 'ts-jest',
  roots: ['<rootDir>/src'],
  testEnvironment: 'node',
  moduleFileExtensions: ['ts', 'js', 'json', 'node'],
};
Run Code Online (Sandbox Code Playgroud)
  • 这是我的 .babelrc
{
  "presets": [
    ["@babel/preset-env", {"targets": {"node": "current"}}],
    "@babel/preset-typescript"
  ],
  "plugins": …
Run Code Online (Sandbox Code Playgroud)

javascript config node.js typescript jestjs

9
推荐指数
1
解决办法
9582
查看次数

标签 统计

config ×1

javascript ×1

jestjs ×1

node.js ×1

typescript ×1