Skip to content

Commit b636734

Browse files
author
nicosammito
committed
feat: add RUNNABLE type and enhance getTypeVariant for function type detection
1 parent 8ae5777 commit b636734

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/extraction/getTypeVariant.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export enum DataTypeVariant {
77
TYPE,
88
ARRAY,
99
OBJECT,
10+
NODE
1011
}
1112

1213
/**
@@ -37,7 +38,9 @@ export const getTypeVariant = (
3738
if (ts.isVariableDeclaration(node) && node.name.getText() === "val") {
3839
const type = checker.getTypeAtLocation(node);
3940

40-
if (checker.isArrayType(type)) {
41+
if (type.getCallSignatures().length > 0) {
42+
discoveredVariant = DataTypeVariant.NODE;
43+
} else if (checker.isArrayType(type)) {
4144
discoveredVariant = DataTypeVariant.ARRAY;
4245
} else if (
4346
type.isStringLiteral() ||

test/data.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const DATA_TYPES: DataType[] = [
99
{identifier: "HTTP_METHOD", type: `"GET" | "POST" | "PUT" | "DELETE"`},
1010
{identifier: "STRING", type: "string"},
1111
{identifier: "CONSUMER", type: "(item:R) => void", genericKeys: ["R"]},
12+
{identifier: "RUNNABLE", type: "() => void"},
1213
{identifier: "PREDICATE", type: "(item:R) => T", genericKeys: ["R", "T"]},
1314
{
1415
identifier: "NUMBER_ARRAY", type: "LIST<NUMBER>", linkedDataTypes: {

test/getTypeVariant.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,20 @@ describe('getTypeVariant', () => {
2727
// In data.ts ist LIST als T[] definiert
2828
expect(getTypeVariant("LIST<NUMBER>", DATA_TYPES)).toBe(DataTypeVariant.ARRAY);
2929
});
30+
31+
it('sollte NODE für Funktionstypen wie CONSUMER zurückgeben', () => {
32+
// In data.ts ist CONSUMER als (item:R) => void definiert
33+
expect(getTypeVariant("CONSUMER<NUMBER>", DATA_TYPES)).toBe(DataTypeVariant.NODE);
34+
});
35+
36+
it('sollte NODE für Funktionstypen wie RUNNABLE zurückgeben', () => {
37+
// In data.ts ist CONSUMER als (item:R) => void definiert
38+
expect(getTypeVariant("RUNNABLE", DATA_TYPES)).toBe(DataTypeVariant.NODE);
39+
});
40+
41+
it('sollte NODE für Funktionstypen wie PREDICATE zurückgeben', () => {
42+
// In data.ts ist CONSUMER als (item:R) => void definiert
43+
expect(getTypeVariant("PREDICATE<NUMBER, BOOLEAN>", DATA_TYPES)).toBe(DataTypeVariant.NODE);
44+
});
3045
});
3146

0 commit comments

Comments
 (0)