microsoft / microsoft/TypeScript
Allow minimal type checking of JavaScript files
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
I'm in the process of introducing TypeScript support into an enormous, 6-year old web application with a lot of JavaScript files. In order to get the most advantages out of TypeScript while we slowly migrate over (which will likely happen slowly), I'd like the following to be true:
- TypeScript files (
.tsand.tsx) are type checked withstrict: true, so that we get as much useful feedback about TS code as possible. - JavaScript code that imports and then incorrectly uses typed TypeScript code throws a TS error
- Other TypeScript errors in JavaScript files are suppressed, because we haven't had the chance to migrate the file to TypeScript yet. OR, at the least, JavaScript files are type checked with
strict: falseto minimize the number of errors they output.
Primary Suggestion
It would be fantastic if typescript had a "minimalCheckJs" config option that, when set to true, would only check JS files for errors on imported typed code. For example, setting "minimalCheckJs": true, "strict": true in tsconfig.json would have this effect:
# moduleA.ts
function hello(msg) {} # throws "no implicit any" error on "msg" arg
export default function logA(msg: string) {
console.log(msg);
}
# moduleB.js
import logA from './moduleA'
import something from './someJavaScriptFile.js' # does not throw "cannot find module" error
logA(1) # throws TS error, because logA is typed
function logB(msg) { # does not show "no implicit any" error on "msg" arg
console.log(msg);
}
This feature would allow me to convert a file from JS to TS, add types to the file, and immediately be assured that the exported code is being used correctly throughout my entire code base (including JS files). Currently, I can set "checkJs": true, but then I will see thousands of other kinds of errors that TypeScript finds in the JS files, such as cannot find module errors.
Alternative Suggestion
If the above feature is difficult to implement, a less ideal but also helpful feature would be to allow setting "strict": false for JS files and "strict": true for TS files. Some way to combine the following:
# strictly type check TS files
{
"compilerOptions": {
"checkJs": false,
"allowJs": true,
"strict": true
},
"include": ["**/*.ts", "**/*.tsx"],
}
# type check JS files with strict: false
{
"compilerOptions": {
"checkJs": true,
"allowJs": true,
"strict": false
},
"include": ["**/*.js", "**/*.jsx"],
}
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、checkJs、allowJs、strict などの tsconfig.json オプションが JavaScript ファイルと TypeScript ファイルに対してどのように解釈されるかを調べます。issue ではソースファイル、テスト、コンパイラーのエントリポイントが特定されていないため、最初に既存の checkJs と strict の処理を追跡してください。完了の条件は、JavaScript がインポートされた型付き TypeScript コードのエラーを報告し、関係のない JavaScript の診断を抑制するとともに、要求された設定をカバーしていることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100