microsoft / microsoft/TypeScript

Declare type to be an import depending on a string literal argument: typeof import(name);

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

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

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

説明

Hello,
It's seems to be difficult to do but there's now a lot of possibilities with the typescript compiler that I wouldn't have thought possible before, so I prefer to ask.

Is there a chance to have this kind of definition:

declare function require(name: string): typeof import(name) | undefined;

I mean declaring the return type as the type coming from the import of module "name". So we could have the type returned by require:

var module = require("my module");

I guess if it's feasible, it will also be possible to add more typing on this kind of javascript code

define("myModule, ["deps1", "deps2", "deps3"], (deps1, deps2, deps3) => {
// deps1, deps2, deps3 have the right type !!
});

like this

define("myModule, ["deps1", "deps2", "deps3"], (deps1: typeof import("deps1"), deps2: typeof import("deps2"), deps3: : typeof import("deps3")) => {
// deps1, deps2, deps3 have the right type !!
});

Thanks for your help,

--
Laurent

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

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

はじめの一歩

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

調査の方向性

まず、TypeScript コンパイラーが typeof import(name) を文字列リテラルに依存させ、その結果を require と define の呼び出しに使用できるかどうかを調査します。issue の例を確認し、必要な言語および型チェックの変更を判断します。完了の条件は、要求されたモジュール型がリテラル引数から推論されることです。

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

評価

技術スタック
typescript
領域
compilers
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

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

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