Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
chore: wip

chore: wip

chore: wip

chore: wip

chore: wip

chore: wip
  • Loading branch information
chrisbbreuer committed Oct 25, 2024
1 parent 161dc9a commit db92cdd
Show file tree
Hide file tree
Showing 2 changed files with 459 additions and 302 deletions.
83 changes: 16 additions & 67 deletions fixtures/output/example-0001.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,20 @@ import type { BunPlugin } from 'bun'
import type { DtsGenerationConfig, DtsGenerationOption } from '@stacksjs/dtsx'
import { generate } from '@stacksjs/dtsx'

/**
* Example of const declaration
*/
export const conf: { [key: string]: string } = {
apiUrl: 'https://api.stacksjs.org',
timeout: '5000', // as string
}
export declare const conf: { [key: string]: string };
export declare const someObject: {
someString: 'Stacks';
someNumber: 1000;
someBoolean: true;
someFalse: false;
someFunction: (...args: any[]) => void;
anotherOne: (...args: any[]) => string;
someFunction: (...args: any[]) => unknown;
anotherOne: (...args: any[]) => unknown;
someArray: Array<1 | 2 | 3>;
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 | unknown | (...args: any[]) => unknown> | Array<4 | 5 | 6 | 7 | 8 | 9 | 10>>;
someComplexArray: Array<Array<{ key: 'value' }> | Array<{ key2: 'value2' } | 'test' | 1000> | Array<'some string' | unknown>>;
someObject: {
key: 'value';
};
Expand All @@ -30,79 +24,39 @@ export declare const someObject: {
nestedKey: 'value';
};
otherKey: {
nestedKey: (...args: any[]) => void;
nestedKey: unknown;
nestedKey2: (...args: any[]) => unknown;
};
};
someNestedObjectArray: Array<{ key: 'value' } | { key2: 'value2' }>;
someOtherObject: unknown;
someInlineCall2: (...args: any[]) => void;
someInlineCall3: (...args: any[]) => void;
};
/**
* Example of interface declaration
* with another comment in an extra line
*/
export interface User {
export declare interface User {
id: number
name: string
email: string
}
/**
* Example of type declaration
*
* with multiple lines of comments, including an empty line
*/
export interface ResponseData {
export declare interface ResponseData {
success: boolean
data: User[]
}
/**
* Example of function declaration
*
*
* with multiple empty lines, including an empty lines
*/
export function fetchUsers(): Promise<ResponseData> {
return fetch(conf.apiUrl)
.then(response => response.json()) as Promise<ResponseData>
}
export declare function fetchUsers(): Promise<ResponseData>;
export declare interface ApiResponse<T> {
status: number
message: string
data: T
}
/**
* Example of another const declaration
*
* with multiple empty lines, including being poorly formatted
*/
const settings: { [key: string]: any } = {
theme: 'dark',
language: 'en',
}
declare const settings: { [key: string]: any };
export declare interface Product {
id: number
name: string
price: number
}
/**
* Example of function declaration
*/
export function getProduct(id: number): Promise<ApiResponse<Product>> {
return fetch(`${settings.apiUrl}/products/${id}`)
.then(response => response.json()) as Promise<ApiResponse<Product>>
}
export declare function getProduct(id: number): Promise<ApiResponse<Product>>;
export declare interface AuthResponse {
token: string
expiresIn: number
}
export declare type AuthStatus = 'authenticated' | 'unauthenticated'
export function authenticate(user: string, password: string): Promise<AuthResponse> {
return fetch('/auth/login', {
method: 'POST',
body: JSON.stringify({ user, password }),
}).then(response => response.json()) as Promise<AuthResponse>
}
export declare type AuthStatus = 'authenticated' | 'unauthenticated';
export declare function authenticate(user: string, password: string): Promise<AuthResponse>;
export declare const defaultHeaders: {
'Content-Type': 'application/json';
};
Expand All @@ -112,20 +66,16 @@ declare interface Options<T> {
cwd?: string
defaultConfig: T
}
export declare function loadConfig<T extends Record<string, unknown>>(options: Options<T>): Promise<T>;
export declare function loadConfig<T extends Record<string, unknown>(): void;
declare const dtsConfig: DtsGenerationConfig;

export { generate, dtsConfig }
export type { DtsGenerationOption }

export { config } from './config'

export * from './extract'
export * from './generate'

export * from './types'
export * from './utils'

// 1. Complex Generic Types
export declare interface ComplexGeneric<T extends Record<string, unknown>, K extends keyof T> {
data: T
key: K
Expand All @@ -139,4 +89,3 @@ export declare type ComplexUnionIntersection =
& {
metadata: Record<string, unknown>
}
export default dts
Loading

0 comments on commit db92cdd

Please sign in to comment.