YousefED / typescript-json-schema

Generate json-schema from your Typescript sources
BSD 3-Clause "New" or "Revised" License
3.17k stars 323 forks source link

Fix recursive intersecting types bug with noExtraProps, probably fixes Issue #281 #526

Closed mambla closed 1 year ago

mambla commented 1 year ago

This fixes a bug that occurs when using recursive and intersecting types with the noExtraProps flag at the same time. For example:

type BNode = {
    node?: BNode;
}

type ANode = {
    val: number;
} & BNode;

type CNode = {
    val: string;
} & BNode;

type Tree = {
    a: number;
    $schema?: string;
} & (CNode | ANode);

The bug occurs because when iterating over the intersecting types, if one of the types is recursive it is returned as a ref, and this cannot be added to the type being built. The fix makes sure that in this case, a ref isnt returned

domoritz commented 1 year ago

Please add a test as well.

mambla commented 1 year ago

Added a test, and fixed the original test