microsoft / microsoft/TypeScript
Allow instantion expression with empty arguments
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
🔍 Search Terms
instantiation expression, empty, type arguments
✅ 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 isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
⭐ Suggestion
I would like to be able to instantiate a generic function type with an empty type arguments list.
It would be nice to allow this for generic types, but it's not as necessary, since a generic type is always instantiated in a type context, even if no type arguments list is given. A generic function type needs to be specifically instantiated.
📃 Motivating Example
Here is a generic function where a type parameter has a default. I can get use an instantiation expression to specialize it to a non-generic function.
declare function find1<T, S extends T=T>(Ar:T[], predicate:(t:T)=>t is S): S | undefined;
type Find1Object = typeof find1<object>;
Here is a generic function with only one type parameter. I cannot use an instantiation expression with the default for S:
declare function find2<S extends object = object>(Ar:object[], predicate:(t:object)=>t is S) : S | undefined;
type Find2 = typeof find2<>; // <- this is a syntax error "Type argument list cannot be empty"
💻 Use Cases
- What do you want to use this for?
- What shortcomings exist with current approaches?
- What workarounds are you using in the meantime?
- Declare an unused "dummy" type parameter so there's always a non-defaulted type argument.
Originally mentioned here: https://github.com/microsoft/TypeScript/issues/57463#issuecomment-1957739330
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Issue ではファイルもテストも指定されていません。まず、インスタンス化式の parser と型チェックのパス、および空の型引数リストを拒否している診断を見つけてください。受け入れ条件として find2 の例を使用します。空のリストは受け入れられ、出力される JavaScript を変更せずに、デフォルト値を使ってジェネリック関数を特殊化できる必要があります。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 42/100