Skip to content

Opening or closing an unsaved dependency leaves stale diagnostics after a large file-watch batch #65638

Open

Description

TypeScript Version

typescript@7.1.0-dev.20261123.1 (01f1a75), macOS 27.2.1 arm64. Tested with an LSP client against tsc --lsp --stdio.

User Goal

An editor showed an error that referred to an older version of an imported file. I wanted to check whether the stock TypeScript language server updates the importer when a dependency opens with unsaved text or closes without saving.

Setup and Action

// main.ts
import { value } from "./dep"
export const count: number = value

// dep.ts on disk
export const value: string = "disk"

tsconfig.json contains {"compilerOptions":{"strict":true,"module":"preserve"},"files":["main.ts"]}.

  1. Initialize the server with pull diagnostics and dynamic file-watch registration enabled. Open main.ts and pull its diagnostics. It reports TS2322.
  2. Send a single workspace/didChangeWatchedFiles notification with 1,001 changed paths outside the program. Then open dep.ts with the in-memory text export const value: number = 1 and immediately pull diagnostics for main.ts. The notifications below use standard LSP parameter shapes, with rootUri set to the project directory.
    await client.sendNotification("workspace/didChangeWatchedFiles", {
      changes: Array.from({ length: 1001 }, (_, i) => ({
        uri: rootUri + "/generated/" + i + ".d.ts", type: 2
      }))
    })
    await client.sendNotification("textDocument/didOpen", {
      textDocument: { uri: rootUri + "/dep.ts", languageId: "typescript",
        version: 1, text: "export const value: number = 1" }
    })
    const report = await client.sendRequest("textDocument/diagnostic", {
      textDocument: { uri: rootUri + "/main.ts" }
    })
  3. To test closing, start a fresh session. Open both files with the in-memory text above and pull diagnostics for main.ts (none). Send the same watch notification, close dep.ts without saving, then pull diagnostics for main.ts again.

Expected and Actual Behavior

Action Expected diagnostic on main.ts 999 changed paths 1,001 changed paths
Open the unsaved numeric version None None TS2322
Close it and return to the string on disk TS2322 TS2322 None

Both results repeated in three fresh runs. The watched paths and the content on disk were the same for the open and close tests at each batch size.

Agent Info

Codex desktop (26.1117.41037), GPT-6, TypeScript Report Issue Skill Version 1.0.

Activity

  1. added
    Bug
    Domain: LS: TSServer
    on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDomain: LS: TSServer

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions