microsoft / microsoft/TypeScript

Suggestion: Allow Types in JS Files

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

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

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

説明

I have a large Angular2 project written in JavaScript, in which we use transform-flow-strip-types in order to allow Angular2 dependency injection to work from JavaScript.

This is currently an error in a JavaScript file compiled with tsc:

class MyClass {
  prop:string;                   //err: 'types' can only be used in a .ts file
  constructor(x: string) {       //err: 'types' can only be used in a .ts file
  }

  someMethod():string {        //err: 'types' can only be used in a .ts file
  }
}

I would like an allowTypesInJsFiles compiler option which would allow us to compile JavaScript files which contain types. All of the above errors would be valid if the flag is set. This would allow us to use Angular2 DI from JavaScript files.

I have a branch with a simple implementation which I have verified to work.

Is this a change which could be accepted? If so I will add tests and sign the CLA.

I think it would be very useful for people migrating large JavaScript projects to TypeScript.

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

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

はじめの一歩

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

調査の方向性

まず、コミット 57a69d880251088d550500dcb018fc4e53895916 の提案された実装と、この issue の例を確認します。コンパイラオプションが型付き JavaScript にどのような影響を与えるべきかを判断し、示されている宣言を対象とするテストを追加して、そのオプションを有効にしたときにコンパイルされることを確認します。

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

評価

技術スタック
javascript, typescript
領域
compilers
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
30/100

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

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