microsoft / microsoft/TypeScript

lib.dom.d.ts seems to not be referenced when any file in the compilation contains no-default-lib=true triple slash

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

@sheetalkamat がすでに取り組んでいます。

2024年2月25日 から。

Needs Investigation
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

🔎 Search Terms

no-default-lib lib dom ignored cannot resolve HTMLElement paths

🕗 Version & Regression Information

This is an unintuitive error that took me a long time to pin down.

⏯ Playground Link

No response

💻 Code

Given the following 3 files:

worker.d.ts

/// <reference no-default-lib="true"/>
/// <reference lib="webworker" />
/// <reference lib="esnext" />

export declare class MyWorker {}

library.d.ts

import type { MyWorker } from "./worker";

export interface Type1 {
  worker: MyWorker;
}

app.d.ts

interface App {
  prop: HTMLElement;
}

tsconfig.json

{
  "compilerOptions": {
    "lib": [ "ES2020", "DOM" ],
  },
}
🙁 Actual behavior

An error occurs in the app.d.ts file

Cannot find name 'HTMLElement'.ts(2304)
🙂 Expected behavior

Any of the following:

  • A better error message inside the app.d.ts file
  • an error in the tsconfig
  • a better error message when using --traceResolution

Suggesting a reason for why lib: [ "DOM" ] in the tsconfig file is ignored.

Its also possible this is incorrect behaviour, however the docs say document that the use case for no-default-lib is for files that do not include the default library, rather than those (like in my case) that wanted to ignore the default libraries included via the tsconfig.json.

Additional information about the issue

This bug is really here as a helpful hint in case anyone else runs into this same issue. Its particularly difficult to debug the issue, as app.d.ts has no references to anything. In my real project, the situation is a bit more complicated, and it took me a long time to figure out that this was the issue.

As a side note, what is the best way to do typings for a web worker file within an existing project? At the moment, I'll be adding a separate tsconfig file for the specific web worker, and exclude that file from the main tsconfig, EDIT: This doesn't actually work, as each separate tsconfig file cannot include files from the other when composite is true.

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

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

はじめの一歩

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

評価

この issue はまだ評価されていません。

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

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