hyperweb-io / hyperweb-io/ts-codegen

[Proposal] Defining a way to discriminated unions in interfaces

Aperta
#108 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
TypeScript
Stelle
126
Fork
31
Merge medio
19m
PR unite (30g)
2

Descrizione

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.

![image](https://github.com/CosmWasm/ts-codegen/assets/40375118/7ad96eba-efe6-4134-a1d3-0e44a63dc26a)

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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.