Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/extraction/getTypeVariant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum DataTypeVariant {
TYPE,
ARRAY,
OBJECT,
NODE
}

/**
Expand Down Expand Up @@ -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() ||
Expand Down
1 change: 1 addition & 0 deletions test/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<NUMBER>", linkedDataTypes: {
Expand Down
15 changes: 15 additions & 0 deletions test/getTypeVariant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,20 @@ describe('getTypeVariant', () => {
// In data.ts ist LIST als T[] definiert
expect(getTypeVariant("LIST<NUMBER>", 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<NUMBER>", 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<NUMBER, BOOLEAN>", DATA_TYPES)).toBe(DataTypeVariant.NODE);
});
});