diff --git a/src/extraction/getTypeVariant.ts b/src/extraction/getTypeVariant.ts index 9efabe7..139d7e3 100644 --- a/src/extraction/getTypeVariant.ts +++ b/src/extraction/getTypeVariant.ts @@ -7,6 +7,7 @@ export enum DataTypeVariant { TYPE, ARRAY, OBJECT, + NODE } /** @@ -37,7 +38,9 @@ export const getTypeVariant = ( if (ts.isVariableDeclaration(node) && node.name.getText() === "val") { const type = checker.getTypeAtLocation(node); - if (checker.isArrayType(type)) { + if (type.getCallSignatures().length > 0) { + discoveredVariant = DataTypeVariant.NODE; + } else if (checker.isArrayType(type)) { discoveredVariant = DataTypeVariant.ARRAY; } else if ( type.isStringLiteral() || diff --git a/test/data.ts b/test/data.ts index 169a10e..be9a0f8 100644 --- a/test/data.ts +++ b/test/data.ts @@ -9,6 +9,7 @@ export const DATA_TYPES: DataType[] = [ {identifier: "HTTP_METHOD", type: `"GET" | "POST" | "PUT" | "DELETE"`}, {identifier: "STRING", type: "string"}, {identifier: "CONSUMER", type: "(item:R) => void", genericKeys: ["R"]}, + {identifier: "RUNNABLE", type: "() => void"}, {identifier: "PREDICATE", type: "(item:R) => T", genericKeys: ["R", "T"]}, { identifier: "NUMBER_ARRAY", type: "LIST", linkedDataTypes: { diff --git a/test/getTypeVariant.test.ts b/test/getTypeVariant.test.ts index 9ff5d27..08a1423 100644 --- a/test/getTypeVariant.test.ts +++ b/test/getTypeVariant.test.ts @@ -27,5 +27,20 @@ describe('getTypeVariant', () => { // In data.ts ist LIST als T[] definiert expect(getTypeVariant("LIST", DATA_TYPES)).toBe(DataTypeVariant.ARRAY); }); + + it('sollte NODE für Funktionstypen wie CONSUMER zurückgeben', () => { + // In data.ts ist CONSUMER als (item:R) => void definiert + expect(getTypeVariant("CONSUMER", DATA_TYPES)).toBe(DataTypeVariant.NODE); + }); + + it('sollte NODE für Funktionstypen wie RUNNABLE zurückgeben', () => { + // In data.ts ist CONSUMER als (item:R) => void definiert + expect(getTypeVariant("RUNNABLE", DATA_TYPES)).toBe(DataTypeVariant.NODE); + }); + + it('sollte NODE für Funktionstypen wie PREDICATE zurückgeben', () => { + // In data.ts ist CONSUMER als (item:R) => void definiert + expect(getTypeVariant("PREDICATE", DATA_TYPES)).toBe(DataTypeVariant.NODE); + }); });