hyperweb-io / hyperweb-io/ts-codegen

[Proposal] Defining a way to discriminated unions in interfaces

Open
#108 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
126
Forks
31
Avg merge
19m
Merged PRs (30d)
2

Description

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.