type callbacks

オープン
#29,755 コメント 3 件 リアクション 1 件 担当者 0 名 GitHub で見る

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

評価

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

調査の方向性

まず、この issue で提案されている type-callback の例と、中間型を扱っているリンク先の issue #23188 を読んでください。この issue では実装ファイルやテストは指定されておらず、定義済みの変更ではなく議論が求められています。作業を完了するには、type-callback をどのように表現し適用するかについて合意された提案が必要です。

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

説明

Needs Proposal Suggestion

search: https://www.google.com/search?q=type+functions+site%3Ahttps%3A%2F%2Fgithub.com%2FMicrosoft%2FTypeScript

The more I work with advance types the more apparent the following problems become:

No intermediate types

At the current stage the advanced types are represented via expressions. Quite often there is a need to reuse exactly the same part of such expression in more than one place. Currently there is no way to capture a part of it and reuse it, consider:

type A<X> = { x: B<X>, y: B<X> }

here I wish I could save B<X> into a local type C somehow to be able to write

// speculative syntax:
type A<X> = <
    type C = B<X>;
    { x: C, y: C };
>;

per @RyanCavanaugh intermediate types are covered by https://github.com/Microsoft/TypeScript/issues/23188

No way to specify a type callback

Currently type parameters are the only way to define a parametric type. There is no way to define a type based on a type callback:

interface Z { x: string; y: number; }
// speculative syntax:
type A<T, F: X =>...,  T> =  { [P in keyof T]: F<T[P]>; } // <-- wish could do this
type B = A<Z, X => X extends string ? true : false>;  // { x: true; y: false; }
type C = A<Z, X => { get: () => X }>;  // { x: { get: () => string; }; y: { get: () => number; }; }

I am not sure what a proposal would be, but these problems are definitely worth a discussion

主要言語
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 を短くまとめたダイジェスト。