Skip to content

How can I force VSCode TypeScript auto-imports to use .ts extension instead of .js? #62636

@fushihara

Description

@fushihara

Acknowledgement

  • I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.

Comment

I was guided here from typescript-language-server/typescript-language-server#1028 , so I’m following up on my question here.

In VSCode 1.105 with TypeScript, auto-completion for symbols sometimes inserts imports with a .js extension and other times with .ts. This inconsistency is problematic for my project.

Example:

  • export-a.ts:
export function exportA() {}
  • In import-a.ts, when I select the completion for exportA, VSCode may insert either:
import { exportA } from "./export-a.js";

or:

import { exportA } from "./export-a.ts";

My goal is one of the following:

  1. A clear, documented rule explaining how the extension is chosen; or
  2. A reliable configuration to force one extension (preferably .ts for my project), so the result is deterministic.

Project context:

  • tsconfig.json includes "allowImportingTsExtensions": true and "noEmit": true.
  • In Node.js v24, importing .ts files works without special flags; rewriting to .js can cause runtime errors.
  • I understand some bundlers prefer .js, and that can make sense in other setups. But in this project, I want imports to remain .ts.

Things I’ve observed but can’t fully explain:

  • If the active file already contains at least one import ... from "./*.ts", subsequent auto-imports seem more likely to stay as .ts.
  • Behavior appears cached until I run Developer: Reload Window.

Questions:

  • What is the exact decision logic for choosing .js vs .ts in auto-imports?
  • Is there an official setting (VSCode or TypeScript) to always generate .ts (or always .js) for auto-imports?
  • If this behavior is intended, can the rule be documented so users can predict and configure it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs More InfoThe issue still hasn't been fully clarified

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions