microsoft / microsoft/TypeScript

Typescript Server syntax highlighting bug: introduced by recent update

未关闭
#63,382 3 条评论 3 个 reaction 已指派 1 人 在 GitHub 查看

@mjbvz 已经在做这个了。

开始于 2026年4月8日。

主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
132

描述

Does this issue occur when all extensions are disabled?: Yes

- VS Code Version: 1.115.0 (Universal) — Commit 41dd792b5e652393e7787322889ed5fdc58bd75b — 2026-04-07
- OS Version: macOS Tahoe 26.1 — Darwin arm64 25.1.0

**Environment:**
- TypeScript: 6.0.2
- React: 19.2.4
- Vite: 8.0.3

Steps to Reproduce:

1. Create a `@types/common/index.d.ts` at the project root using the `declare global {} export {}` pattern to declare global types (e.g. `IUser`).
2. Configure `tsconfig.json` with `typeRoots` pointing to the directory and `include` set to only `["src"]`:
```json
{
"compilerOptions": {
"typeRoots": ["./node_modules/@types", "./@types"]
},
"include": ["src"]
}
```
3. Reference a global type (e.g. `IUser`) in any `.tsx` file inside `src/`.
4. Observe red syntax highlighting: `Cannot find name 'IUser'`.
5. Run **TypeScript: Restart TS Server** — error persists.
6. Run **Developer: Reload Window** — error persists.

**Expected:** TypeScript Server resolves global types from `typeRoots` and shows no syntax highlighting errors.

**Actual:** TypeScript Server fails to resolve global types from `typeRoots` when the directory is outside `include`, producing incorrect `Cannot find name` syntax highlighting errors. The project runs without errors at runtime.

**Workaround:** Adding the `typeRoots` directory explicitly to `include` resolves the syntax highlighting errors:

```json
"include": ["src", "./@types"]
```

`typeRoots` alone should be sufficient for the TypeScript Server to resolve these types.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。