microsoft / microsoft/TypeScript

TypedPropertyDescriptorMap<T>

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

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

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

説明

Search Terms

TypedPropertyDescriptor
TypedPropertyDescriptorMap
Typed Property Descriptor Map

Suggestion

Include TypedPropertyDescriptorMap<T>, the typed version of PropertyDescriptorMap. The following type should do the trick:

type TypedPropertyDescriptorMap<T> = {
  [P in keyof T]: TypedPropertyDescriptor<T[P]>
}

This would require a change to the Object.defineProperties type definition since it only accepts a PropertyDescriptorMap type, an indexed type. Passing in an object with a type of TypedPropertyDescriptorMap<T> results in the error: Index signature is missing in type 'TypedPropertyDescriptorMap<T>'. There's a related issue on this topic (https://github.com/Microsoft/TypeScript/issues/15300).

Use Cases

It's a headache to have to define a type like the following when I already have defined the final object type:

// Final object looks like
interface MyProps {
  prop1: string
  prop2: (params: Record<string, string>) => Promise<void>
}

// My custom TypedPropertyDescriptor map
interface MyPropDescriptors {
  prop1: TypedPropertyDescriptor<MyProps['prop1']>
  prop2: TypedPropertyDescriptor<MyProps['prop2']>
  ...
}

Examples

// Final object looks like
interface MyProps {
  prop1: string
  prop2: (params: Record<string, string>) => Promise<void>
}

// My custom TypedPropertyDescriptor map
type MyPropDescriptors = TypedPropertyDescriptorMap<MyProps>

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, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

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

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

はじめの一歩

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

調査の方向性

まず、Object.defineProperties の宣言と、既存の TypedPropertyDescriptor および PropertyDescriptorMap 型を見つけます。関連する issue #15300 を確認し、続いて提案された mapped type と、それが Object.defineProperties に受け入れられることを、対象を絞った type-checking test で検証します。typed descriptor maps が index-signature error なしで機能すれば完了です。

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

評価

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

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

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