microsoft / microsoft/TypeScript
Implement type Require to set specified Optional properties in an interface as Required
オープン
まだ誰も着手していません。
Awaiting More Feedback
Suggestion
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Suggestion
TS interfaces such as Omit, Pick are doing great job helping us re-use current interfaces rather than re-writing them. One interface that I needed today was one to help me set specific property of another as Required. I did my search and it seems such a thing is not implemented. So, I tried and came up with this:
type Require<T, K extends keyof T> = T & { [P in K]: Required<P> };
interface IOptionalProps {
prop1: string; // required by default
prop2?: string // optional by default
prop3?: string // //
}
const foo: Require<IOptionalProps, 'prop2'> = { prop1: 'foo', prop2: 'foo', }; // prop2 can't be left behind
const foobar: Require<IOptionalProps, 'prop2'> = { prop1: 'baz', prop2: 'baz', prop3: 'baz', }; //all props can't be left behind
🔍 Search Terms
- interface require
- interface required
- transform optional required
✅ Viability Checklist
My suggestion meets these guidelines:
- 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
- Review the provided snippet.
- Add it to TS if it goes well with the TS.
📃 Motivating Example
Provided as part of the suggestion.
💻 Use Cases
Provided as part of the suggestion.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、提案されている Require<T, K extends keyof T> の定義と、その IOptionalProps の例を確認します。要求されたユーティリティ型が TypeScript の既存のユーティリティ型の設計に適合するかを判断し、適切なコンパイラテストとドキュメントを特定します。採用された場合に、動作が仕様化され、テストされ、ドキュメント化されていれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 30/100