microsoft / microsoft/vscode-generator-code
yo code TypeScript template missing "types": ["mocha"] after TypeScript 6.0 change
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 undernode_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
- Run
yo codeand choose a TypeScript extension. - Open the generated project in VS Code.
- Observe red errors on
suiteandtestinsrc/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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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