microsoft / microsoft/TypeScript

checkJs: x.js should use x.d.ts for type inference

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

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

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

説明

Suggestion

🔍 Search Terms

checkjs, declaration files

✅ Viability Checklist

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

If a declaration file with the same name than a JavaScript file is available (in the same location), then the declaration file should be used to check the js file.

📃 Motivating Example

Assume that "checkJs" and "strict" options are enabled.

Given the following files:

// @filename a.d.ts
export function f(n: number): number;
// @filename a.js
function f(a) {
    // Parameter 'a' implicitly has an 'any' type
    return a + 1
}

the type of f should be inferred and should thus type-check. TSC does not currently use a.d.ts to infer types of a.js.
Note that importing f in another js file, already infer f's type

// @filename b.js
import { f } from "./a.js"
// type of f is inferred

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

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

はじめの一歩

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

調査の方向性

a.d.ts、a.js、b.jsを使ったcheckJsおよびstrictの再現コードから始め、次にTypeScriptのcheckerをそれに対して実行して現在の診断を確認します。インポートされたfに対して宣言ファイルがどのように解決されるかを追跡し、それをa.jsを直接チェックした場合と比較します。a.jsの型チェックに同名の宣言が使用され、出力されるJavaScriptが変更されなければ完了です。

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

評価

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

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

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