microsoft / microsoft/TypeScript

TypeScript 3.9: Type files are behaving like included files

オープン
#38,079 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Needs Investigation
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

I'm trying to use the new TypeScript code editor support for solution projects and it's working pretty well, but has the issue mentioned in the title.

When I add typeRoots or a type file, the referenced file isn't used just to get types from it. Instead, it acts like an included file for that project and the file's type checking follows that project configuration in the editor.

tsconfig.json

{
  "files": [],
  "references": [
    {
      "path": "./tsconfig.client.json"
    },
    {
      "path": "./tsconfig.server.json"
    },
    {
      "path": "./tsconfig.shared.json"
    }
  ]
}

tsconfig.base.json

{
  "compilerOptions": {
    "baseUrl": "./",
    "composite": true,
    "declarationDir": "./@types",
    "emitDeclarationOnly": true,
    "lib": [
      "ES5"
    ],
    "target": "ES5",
    "typeRoots": [
      "node_modules/@types/",
      "lib/types/"
    ]
  }
}

tsconfig.client.json

{
  "extends": "./tsconfig.base.json",
  "compilerOptions": {
    "lib": [
      "ES6",
      "DOM"
    ],
    "target": "ES6",
    "types": [
      "client",
      "shared" // This line is the problem
    ]
  },
  "exclude": [
    "lib/types/shared/"
  ],
  "include": [
    "lib/types/client/"
  ]
}

tsconfig.shared.json

{
  "extends": "./tsconfig.base.json",
  "compilerOptions": {
    "types": [
      "shared"
    ]
  },
  "include": [
    "lib/types/shared/"
  ]
}

lib/types/shared/index.d.ts

type ShouldNotHaveDomLib = Element; // This works, but should output an error

It seems like an issue with VSCode as building the project with "tsc --build" does throw the expected error:

lib/types/shared/index.d.ts:1:28 - error TS2304: Cannot find name 'Element'.

1 type ShouldNotHaveDomLib = Element;

I found that removing the "shared" types from tsconfig.client.json made the client types unavaliable as expected, but then made the server ones avaliable, as the "server" project is the second on the reference list.

With this, I found a very simple solution: put "shared" project as the first referenced in "tsconfig.json"

{
  "files": [],
  "references": [
    {
      "path": "./tsconfig.shared.json"
    },
    {
      "path": "./tsconfig.client.json"
    },
    {
      "path": "./tsconfig.server.json"
    }
  ]
}

This solves the issue for me and yes, building the shared project first should be the standard, so not a huge deal for people using this project pattern. Still, it still is an unexpected behaviour and there might be some other patterns where this is a bigger issue.

I searched for issues here, on TypeScript and Javascript and Typescript Nightly and found nothing, so I apologize if this is a duplicate and/or should be reported to one of those repositories.

  • VSCode Version: 1.44.2 (testes in latest insider too)
  • OS Version: Windows 10 19608

Steps to Reproduce:

  1. Download the Javascript and Typescript Nightly extension
  2. Set up project as above
  3. Add some types to types/client/index.d.ts
  4. Try to use those types in types/server/index.d.ts

Does this issue occur when all extensions are disabled?: No, because I do need the Javascript and Typescript Nightly extension to use TS 3.9 features. However, it still happens while using it with only this extension.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

tsconfig.json、tsconfig.base.json、tsconfig.client.json、tsconfig.shared.json、lib/types/shared/index.d.ts を使用してセットアップを再現し、その後、エディターの動作を tsc --build と比較します。TypeScript エディターが参照された型ファイルとプロジェクト構成をどのように処理するかを調査します。完了条件は、参照されている client と server の型を保持しながら、エディターが Element が見つからないことによる想定どおりのエラーを報告することです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript, vscode
領域
compilers, developer-experience
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。