microsoft / microsoft/TypeScript

allowJs option with namespaces

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

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

Domain: JavaScript Needs Proposal Suggestion
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

I am currently trying to put the compiler option "allowJs" to use. My goal is to convert an existing JavaScript application into TypeScript step by step. The application does not use (external) modules, so I'm converting the JavaScript namespaces into real TypeScript namespaces, but I'm running into "duplicate identifier" errors as outlined below. Shouldn't it be possible to combine TypeScript and JavaScript using the same namespace? Maybe I'm doing something wrong or this is not intended, but I expected this to work.

TypeScript Version: 1.8.10

Code
File 1:

namespace myapp {
    export var c1 = 5;
}

File 2:

var myapp;
(function (myapp) {
    myapp.c2 = 4;
})(myapp || (myapp = {}));

tsconfig.json

{
    "compilerOptions": {
        "allowJs": true,
        "outFile": "dist/appBundle.js"
    }
}

Expected behavior:
Bundling the compiled code of file 1 and the code of file 2 without modifications into a single JavaScript file.

Actual behavior:
The compilation is done, but the compiler throws an error: "error TS2300: Duplicate identifier 'myapp'."

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

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

はじめの一歩

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

調査の方向性

2つのサンプルファイルと提供された tsconfig.json を TypeScript 1.8.10 で使用するところから始め、allowJs、namespaces、outFile によって TS2300 の重複識別子エラーを再現します。完了条件は、JavaScript を変更したり重複識別子を報告したりせずに、TypeScript と JavaScript の namespace コードを1つの JavaScript ファイルにバンドルできることです。

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

評価

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

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

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