Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor - Use TypeScript's variadic tuple types instead of T1,T2,... #757

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
92 changes: 9 additions & 83 deletions packages/core/src/resolvable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,95 +25,21 @@ export namespace AsyncResolvable {
[key in keyof T]: AsyncResolvable<T[key]>;
};

export function resolve<T>(
value: T | DynamicallyResolvable<T> | AsyncDynamicallyResolvable<T>,
): Awaitable<T>;
export function resolve<T>(value: AsyncResolvable<T>): Awaitable<T>;

export function resolve<T1, T2>(
...values: [AsyncResolvable<T1>, AsyncResolvable<T2>]
): Promise<[T1, T2]>;
export function resolve<T extends any[]>(
...values: { [K in keyof T]: AsyncResolvable<T[K]> }
): Promise<{ [K in keyof T]: T[K] }>;

export function resolve<T1, T2, T3>(
...values: [AsyncResolvable<T1>, AsyncResolvable<T2>, AsyncResolvable<T3>]
): Promise<[T1, T2, T3]>;

export function resolve<T1, T2, T3, T4>(
...values: [
AsyncResolvable<T1>,
AsyncResolvable<T2>,
AsyncResolvable<T3>,
AsyncResolvable<T4>,
]
): Promise<[T1, T2, T3, T4]>;

export function resolve<T1, T2, T3, T4, T5>(
...values: [
AsyncResolvable<T1>,
AsyncResolvable<T2>,
AsyncResolvable<T3>,
AsyncResolvable<T4>,
AsyncResolvable<T5>,
]
): Promise<[T1, T2, T3, T4, T5]>;

export function resolve<T1, T2, T3, T4, T5, T6>(
...values: [
AsyncResolvable<T1>,
AsyncResolvable<T2>,
AsyncResolvable<T3>,
AsyncResolvable<T4>,
AsyncResolvable<T5>,
AsyncResolvable<T6>,
]
): Promise<[T1, T2, T3, T4, T5, T6]>;

export function resolve<T1, T2, T3, T4, T5, T6, T7>(
...values: [
AsyncResolvable<T1>,
AsyncResolvable<T2>,
AsyncResolvable<T3>,
AsyncResolvable<T4>,
AsyncResolvable<T5>,
AsyncResolvable<T6>,
AsyncResolvable<T7>,
]
): Promise<[T1, T2, T3, T4, T5, T6, T7]>;

export function resolve<T1, T2, T3, T4, T5, T6, T7, T8>(
...values: [
AsyncResolvable<T1>,
AsyncResolvable<T2>,
AsyncResolvable<T3>,
AsyncResolvable<T4>,
AsyncResolvable<T5>,
AsyncResolvable<T6>,
AsyncResolvable<T7>,
AsyncResolvable<T8>,
]
): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>;

export function resolve<T1, T2, T3, T4, T5, T6, T7, T8, T9>(
...values: [
AsyncResolvable<T1>,
AsyncResolvable<T2>,
AsyncResolvable<T3>,
AsyncResolvable<T4>,
AsyncResolvable<T5>,
AsyncResolvable<T6>,
AsyncResolvable<T7>,
AsyncResolvable<T8>,
AsyncResolvable<T9>,
]
): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>;

export function resolve<T>(...values: AsyncResolvable<T>[]): Awaitable<T> | Promise<T[]> {
export function resolve<T extends any[]>(
...values: { [K in keyof T]: AsyncResolvable<T[K]> }
): Awaitable<T> | Promise<{ [K in keyof T]: T[K] }> {
if (values.length === 1) {
const [value] = values;
return resolveAsyncOne(value);
return resolveAsyncOne(values[0]) as Awaitable<T[0]>;
}

const resolutions = values.map((value) => resolveAsyncOne(value));
return Promise.all(resolutions);
return Promise.all(resolutions) as Promise<{ [K in keyof T]: T[K] }>;
}
}

Expand Down
Loading