microsoft / microsoft/vscode-generator-code

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

Open Beginner friendly
#599 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.6k
Forks
262
Avg merge
15d 22h
Merged PRs (30d)
1

Description

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).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the TypeScript templates that generate tsconfig.json and the scaffolded src/test/extension.test.ts, then run yo code to reproduce the missing suite and test errors. Update the relevant generated configuration with the required Mocha types and verify that a newly generated TypeScript extension compiles without those errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
testing-qa, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.