Giter Club home page Giter Club logo

Comments (4)

kayahr avatar kayahr commented on July 18, 2024

Ran into the same problem...

type Base = {
    a: string;
};

type Variant1 = {
    b: string;
};

type Variant2 = {
    b: number;
};

export type MyObject = Base & (Variant1 | Variant2);

It works when restructuring the type a little bit, so this may be used as a workaround:

export type MyObject = (Base & Variant1) | (Base & Variant2);

from ts-json-schema-generator.

domoritz avatar domoritz commented on July 18, 2024

We should be doing this automatically but it's not trivial to implement with the current architecture.

from ts-json-schema-generator.

kayahr avatar kayahr commented on July 18, 2024

There seems to be another issue with the original example. Even when translating the intersection type manually to A & {x: true} | B & {x: true} it does not yield the correct schema because the restriction of x to true is ignored. It works when swapping the order to {x: true} & A | {x: true} & B. This has nothing to do with unions, can also be reproduced with a simple intersection. I'll create a new issue for this (See #115).

from ts-json-schema-generator.

kayahr avatar kayahr commented on July 18, 2024

I'm closing this issue because the main part of it is fixed now by #116. The still remaining issue with objects not being properly merged together is tracked by issue #115.

from ts-json-schema-generator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.