Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed Oct 22, 2024
1 parent e73671d commit 1533ddf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions fixtures/output/example-0001.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export declare const someObject: {
someNestedArray: Array<Array<1 | 2 | 3> | Array<4 | 5 | 6 | 7 | 8 | 9 | 10>>;
someNestedArray2: Array<Array<1 | 2 | 3> | Array<4 | 5 | 6 | 7 | 8 | 9 | 10> | 'dummy value'>;
someNestedArray3: Array<Array<1 | 2 | 3> | Array<4 | 5 | 6 | 7 | 8 | 9 | 10> | 'dummy value' | Array<11 | 12 | 13>>;
someOtherNestedArray: Array<Array<'some text' | 2 | (...args: any[]) => void | (...args: any[]) => void | unknown> | Array<4 | 5 | 6 | 7 | 8 | 9 | 10>>;
someComplexArray: Array<Array<{ key: 'value' }> | Array<{ key2: 'value2' } | 'test' | 1000> | Array<'some string' | (...args: any[]) => void | unknown>>;
someOtherNestedArray: Array<Array<'some text' | 2 | ((...args: any[]) => void) | ((...args: any[]) => void) | unknown> | Array<4 | 5 | 6 | 7 | 8 | 9 | 10>>;
someComplexArray: Array<Array<{ key: 'value' }> | Array<{ key2: 'value2' } | 'test' | 1000> | Array<'some string' | ((...args: any[]) => void) | unknown>>;
someObject: {
key: 'value';
};
Expand Down
7 changes: 3 additions & 4 deletions src/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,13 +424,12 @@ export function inferElementType(element: string): string {

// Handle function references and calls
if (trimmed === 'console.log' || trimmed.endsWith('.log')) {
return '(...args: any[]) => void'
return '((...args: any[]) => void)'
}

// Handle arrow functions
if (trimmed.includes('=>')) {
const arrowFn = trimmed.match(/\(.*\)\s*=>\s*(.*)/)
return '(...args: any[]) => void'
return '((...args: any[]) => void)'
}

// Handle function calls
Expand Down Expand Up @@ -463,8 +462,8 @@ export function processNestedArray(elements: string[]): string {
const nestedContent = extractNestedContent(trimmed, '[', ']')
if (nestedContent) {
const nestedElements = splitArrayElements(nestedContent)
// Process each nested element to create a proper union type
const nestedTypes = nestedElements.map(ne => inferElementType(ne.trim()))
// Ensure nested array types are properly formatted
return `Array<${nestedTypes.join(' | ')}>`
}
return 'never'
Expand Down

0 comments on commit 1533ddf

Please sign in to comment.