hyperweb-io / hyperweb-io/ts-codegen

[Proposal] Defining a way to discriminated unions in interfaces

Offen
#108 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
TypeScript
Sterne
126
Forks
31
Ø Merge
19 Min.
Gemergte PRs (30 T.)
2

Beschreibung

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

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

The issue provides no repository file or test entry point; start by reproducing the union example from the linked gist and tracing where interface and type generation handles unions. Compare the generated output with the requested generic and conditional-type behavior, including nested unions. Done means the generator supports the proposed discriminated-union interface behavior with coverage for the described cases.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
tooling
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.