Skip to content

Commit e85cc8d

Browse files
author
nicosammito
committed
feat: enhance type variant detection in getTypeVariant with additional test cases
1 parent e16a63d commit e85cc8d

2 files changed

Lines changed: 4 additions & 6 deletions

File tree

src/extraction/getTypeVariant.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,7 @@ export const getTypeVariant = (
4949
) {
5050
discoveredVariant = DataTypeVariant.PRIMITIVE;
5151
} else if (type.isClassOrInterface() || (type.getFlags() & ts.TypeFlags.Object) !== 0) {
52-
// Check if it's literally just a type alias to something else or a complex object
53-
if (type.getProperties().length > 0) {
54-
discoveredVariant = DataTypeVariant.OBJECT;
55-
} else {
56-
discoveredVariant = DataTypeVariant.TYPE;
57-
}
52+
discoveredVariant = DataTypeVariant.OBJECT;
5853
} else {
5954
discoveredVariant = DataTypeVariant.TYPE;
6055
}

test/getTypeVariant.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ describe('getTypeVariant', () => {
1717

1818
it('sollte OBJECT für Interfaces oder Objekte mit Properties zurückgeben', () => {
1919
expect(getTypeVariant("{ name: string }", DATA_TYPES)).toBe(DataTypeVariant.OBJECT);
20+
expect(getTypeVariant("{}", DATA_TYPES)).toBe(DataTypeVariant.OBJECT);
2021
});
2122

2223
it('sollte TYPE für einfache Type-Aliase oder void zurückgeben', () => {
@@ -27,6 +28,7 @@ describe('getTypeVariant', () => {
2728
it('sollte LIST (NUMBER) als ARRAY erkennen (wenn in DATA_TYPES definiert)', () => {
2829
// In data.ts ist LIST als T[] definiert
2930
expect(getTypeVariant("LIST<NUMBER>", DATA_TYPES)).toBe(DataTypeVariant.ARRAY);
31+
expect(getTypeVariant("LIST<unknown>", DATA_TYPES)).toBe(DataTypeVariant.ARRAY);
3032
});
3133

3234
it('sollte NODE für Funktionstypen wie CONSUMER zurückgeben', () => {
@@ -44,6 +46,7 @@ describe('getTypeVariant', () => {
4446
expect(getTypeVariant("PREDICATE<NUMBER>", DATA_TYPES)).toBe(DataTypeVariant.NODE);
4547
});
4648

49+
4750
it("Check if", () => {
4851
const types = getTypesFromNode({
4952
functionDefinition: {

0 commit comments

Comments
 (0)