hyperweb-io / hyperweb-io/ts-codegen
[Proposal] Defining a way to discriminated unions in interfaces
- 主要言語
- TypeScript
- スター
- 126
- フォーク
- 31
- 平均マージ
- 19分
- マージ済み PR(30日)
- 2
説明
Currently now when you have an interface or type that use an union, is really hard to access to the desired property.
In the example below you could see how is not possible to access to a specific property from an union (at least you force the type). However defining generics in the root object and make programmers define the expected union is more much friendly programming experience.

The generation process could be something like:
1. Check for Unions in the object, generate as many generic as unions in the root object and start from A to Z.
2. Generate each type of an union separately.
3. Do conditional type until check all types in the union.
Follow the same process with Unions that have nested Unions.
You could find a full example here: https://gist.github.com/j0nl1/22dde0ef0bfaf1c0bea870a0a39e039e
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
調査の方向性
この issue にはリポジトリのファイルもテストのエントリポイントもないため、まずリンクされた gist の union の例を再現し、interface と type の生成で union がどこで処理されるかを追跡してください。生成された出力を、要求された generic および conditional-type の動作と比較し、ネストされた union も含めて確認してください。説明されているケースをカバーした、提案された discriminated-union interface の動作をジェネレーターがサポートすれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- tooling
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100