Skip to content

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

Description

@beej

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions