Flexibility of template literal types for enums

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

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

評価

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

調査の方向性

まず、issue で提案されている template literal types と enum のキー/値ペア間の相互作用を確認してください。payload ではファイル、テスト、エントリーポイントが指定されておらず、構文とセマンティクスもまだ推測の域を出ていません。完了とするには、enum の順列について設計を確定し、明確な実装および検証計画を定める必要があります。

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

説明

Awaiting More Feedback Suggestion

Search Terms

template literal type enum permutations

Suggestion

Typescript 4.1 brought template literal types, which make it simple to express all the possibilities of permutations of unions of string types concatenated together. It would be cool if there was some equivalent syntax for expressing enum key/value pairs with the same level of expressivity that template literal types provide.

Use Cases

However, my codebase right now uses enums for these kinds of string types, so if I want to express a bunch of permutations of possible values with an enum, I can't really leverage template literal types in this case.

Examples

this is just some syntax I'm making up, I don't know how this would work especially for dealing with keys and values separately:

enum Color {
  RED,
  BLUE
}
enum Shape {
  SQUARE,
  CIRCLE
}
enum ColoredShape {
  [`${keyof Color}_${keyof Shape}`]
}

console.log(ColoredShape.RED_SQUARE, ColoredShape.BLUE_CIRCLE)

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