Skip to content

[Proposal] Defining a way to discriminated unions in interfaces #108

Open
@j0nl1

Description

@j0nl1

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions