Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

yo code TypeScript template missing "types": ["mocha"] after TypeScript 6.0 change

未关闭 适合新手
#599 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
74/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清
技术栈
typescript

调研方向

首先定位生成 tsconfig.json 和脚手架化的 src/test/extension.test.ts 的 TypeScript 模板,然后运行 yo code 以重现缺失的测试套件和测试错误。使用所需的 Mocha 类型更新相关的生成配置,并验证新生成的 TypeScript 扩展可以在没有这些错误的情况下编译。

由索引模型根据 Issue 内容生成。

描述

Problem

When creating a new TypeScript extension with yo code, the generated project installs @types/mocha in devDependencies but does not add "mocha" to the "types" field in tsconfig.json.

This causes immediate TypeScript errors in the scaffolded test file:

Cannot find name 'suite'. Do you need to install type definitions for a test runner? Try npm i --save-dev @types/mocha and then add 'mocha' to the types field in your tsconfig.
Cannot find name 'test'. Do you need to install type definitions for a test runner? ...

Related Issue

This is closely related to #575 (“TypeScript cannot find Node globals with default VSCode tsconfig”). Both issues stem from the same TypeScript 6.0 change to the default "types" behavior.

Root Cause

TypeScript 6.0 changed the default behavior of the "types" compiler option:

  • Before TS 6: Omitting "types" automatically included all packages under node_modules/@types.
  • TS 6+: The default is now an empty array ("types": []). Packages must be listed explicitly.

The current yo code template was written for the old behavior and was never updated for this breaking change.

Expected Behavior

The generated tsconfig.json (or the relevant test tsconfig) should include:

"compilerOptions": {
...
"types": ["mocha", "node"]
}

(or at least "mocha").

Steps to Reproduce
  1. Run yo code and choose a TypeScript extension.
  2. Open the generated project in VS Code.
  3. Observe red errors on suite and test in src/test/extension.test.ts.
Suggested Fix

Update the TypeScript templates in generator-code so that the generated tsconfig.json explicitly lists the required types (mocha and usually node).

主要语言
JavaScript
星标
1.6k
派生
262
平均合并
3 小时 44 分钟
30 天内合并 PR
2

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/vscode-generator-code 的其他 Issue

查看 microsoft/vscode-generator-code 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。