microsoft / microsoft/TypeScript

Incorrect error message on export assignment in `.d.ts` file

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

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

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

説明

TypeScript Version: 3.5.3

Search Terms:

An export assignment cannot be used in a namespace.

Code

This is pretty niche, but I think it has general implications...

The current /lib/typescript.d.ts file is modelled as essentially a CommonJS file where at the end of the file, it has export = ts; which exports the whole namespace. The actual /lib/typescript.js though will place itself in the global scope as ts if it isn't loaded as a CommonJS module. In order to express that ts is available as a global variable, it requires code like this to be placed in a .d.ts file:

import * as _ts from "typescript";

declare global {
  namespace ts {
    export = _ts;
  }
}

Other methods of expressing this, like declare var ts: typeof _ts; only make the function shape of ts available, while the interfaces and type aliases and other type information is not accessible.

Expected behavior:

No errors.

Actual behavior:

The error TS1063: An export assignment cannot be used in a namespace occurs, but in VSCode, if the file is named globals.d.ts this error does not occur. 🤷‍♂ In all cases the code above does work like expected, making both the functional and type exports of the namespace available for code to be checked against.

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

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

はじめの一歩

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

調査の方向性

まず、提供された宣言スニペットで診断を再現し、次にファイル名を globals.d.ts にした場合の動作と比較します。/lib/typescript.d.ts の関連する宣言と、/lib/typescript.js のランタイムコンテキストを読みます。有効なパターンがエラーを報告せず、機能エクスポートと型エクスポートの両方を維持できれば完了です。

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

評価

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

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

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