microsoft / microsoft/TypeScript

Make ParameterDecorator and the like generic

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

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

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

説明

lib Update Request

Missing / Incorrect Definition

ParameterDecorator is currently not generic, it can be attachted to any parameter. However, when a decorator is used for e.g. Dependency Injection purposes, some decorators require the type of the parameter to be consistent with the type of the decorator

Sample Code

E.g. we want this to work

class MyController {
  requestThings(@UserId() userId: number): Thing[] { return [] }
}

But this to fail:

class MyController {
  requestThings(@UserId() userId: string): Thing[] { return [] }
}

(as userId will be a number, not a string so the injection should ideally not be possible (at compile time)

Currently UserId is done more or less this way:

const UserId = (): ParameterDecorator => (target, key, index) => { 
  // do stuff
}

while I'd like to add number to ParameterDecorator:

const UserId = (): ParameterDecorator<number> => (target, key, index) => { 
  // do stuff
}

and I'd like typescript to check this when applying a decorator.

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

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

はじめの一歩

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

調査の方向性

まず、ParameterDecorator の定義と、パラメーターデコレーターの適用に関するコンパイラーのチェックを見つけます。Issue の number と string の例を現在の動作と比較し、そのうえで、ジェネリックなパラメーター型をどのように表現し、検証すべきかを判断します。妥当なデコレーターの適用が受け入れられ、型が一致しないパラメーター型が適切なテストによって拒否されれば完了です。

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

評価

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

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

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