Allow decorated accessor properties to have a different type

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

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

評価

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

調査の方向性

リンクされた TypeScript playground と関連する issue #52559 から始めて、現在の動作とこれまでの議論を比較します。動機となった Demo の例を受け入れ条件として使用します。this.num が number として推論された状態で型チェックを通過し、既存のランタイム動作が維持されれば完了です。

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

説明

Awaiting More Feedback Suggestion
🔍 Search Terms

I was pretty sure an issue already existed for this, but I couldn't find it. Hopefully opening a new issue (to maybe be closed again) will improve SEO.

Here is what I searched for:

  • decorators change type
  • decorators accessor type
  • decorators change type accessor

I did find this related issue:

✅ Viability Checklist
⭐ Suggestion

Allow decorator's return type, ClassAccessorDecoratorResult to specify a different Value-type than what is on the right-hand side of the equals.

Here is how TS 5.6.3 handles this situation today.

📃 Motivating Example

For example, it should be possible to author this with 0 errors:

class Demo {
  @unwrap accessor num = { wrapped: 2 };
  //               ^? => number

  get usage() {
    expectTypeOf(this.num).toEqualTypeOf<number>();
  }
}
💻 Use Cases
  1. Reactivity
  2. Hiding complex behaviors from the user
  3. Unwrapping private objects into public API (the example in the playground link)
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

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

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

はじめの一歩

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

microsoft/TypeScript のほかの issue

microsoft/TypeScript の issue をすべて見る

似ている issue

Go の issue をもっと見る

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

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