Union of object properties not working
type Original = {
propA?: string;
propB?: string;
};
type Unioned = Original & {
propB?: string[];
};
Clicking on Unioned doesn't update the type tree with the type.
I'm able to reproduce this. The simplest case seems to just be,
type Union = string & string[];
It crashes with the following error in the console:
TypeTreeRequest error TypeError: Cannot read properties of undefined (reading 'name')
The error occurs here: https://github.com/mxsdev/ts-type-explorer/blob/main/packages/api/src/tree.ts#L438
@mxsdev, could this simply be due to the change in TypeScript 5.2? https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#labeledelementdeclarations-may-hold-undefined-elements
In order to support a mixture of labeled and unlabeled elements, TypeScript’s API has changed slightly. The
labeledElementDeclarationsproperty ofTupleTypemay holdundefinedfor at each position where an element is unlabeled.
I just changed it to this and @swingthrough's test case didn't crash:
).labeledElementDeclarations?.map((s) =>
s ? s.name.getText() : "(unnamed tuple index)"
),
(I put "(unnamed tuple index)" just to see where it occurred, but a more proper value would probably be "")
Granted, instead of giving just "undefined", "string", and "string[]", I also got all inherited properties of an array. (But maybe this is correct?)
...
EDIT:
Apparently it's coincidential that this error is occurring for string & string[] and only happens because it generates a nice big tree, and deep inside that tree, there are occurrences of tuples:
The real issue is with tuples in general, as #55 points out.