From d496bff001d6f9c24bcd02f4ceeab7c6e1324052 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Sat, 11 Jan 2025 10:05:35 -0700 Subject: [PATCH] docs: add many type parameter docs --- src/task.ts | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/src/task.ts b/src/task.ts index 8d4e55af..91af6dae 100644 --- a/src/task.ts +++ b/src/task.ts @@ -768,13 +768,14 @@ export type TaskTypesFor = [ The resolution type for a given {@linkcode Task}. @internal */ -export type ResolvesTo = T extends Task ? T : never; +export type ResolvesTo = T extends Task ? Value : never; /** The rejection type for a given {@linkcode Task} @internal */ -export type RejectsWith = T extends Task ? E : never; +export type RejectsWith = + T extends Task ? Rejection : never; /** Create a {@linkcode Task} which will resolve to {@linkcode Unit} after a set @@ -840,6 +841,8 @@ export type All = Task< ``` @param tasks The list of tasks to wait on. + + @template A The type of the array or tuple of tasks. */ export function all(tasks: []): Task<[], never>; export function all(tasks: A): All; @@ -934,6 +937,8 @@ export type Settled = { ``` @param tasks The tasks to wait on settling. + + @template A The type of the array or tuple of tasks. */ export function allSettled(tasks: A): Task, never>; export function allSettled(tasks: AnyTask[]): Task { @@ -991,6 +996,8 @@ export function allSettled(tasks: AnyTask[]): Task { first task to resolve, or {@linkcode Rejected} with the rejection reasons for all the tasks passed in in an {@linkcode AggregateRejection}. Note that the order of the rejection reasons is not guaranteed. + + @template A The type of the array or tuple of tasks. */ export function any(tasks: []): Task>; export function any( @@ -1066,6 +1073,8 @@ export function any(tasks: [] | AnyTask[]): AnyTask { ``` @param tasks The tasks to race against each other. + + @template A The type of the array or tuple of tasks. */ export function race(tasks: []): Task; export function race( @@ -1094,6 +1103,8 @@ export function race(tasks: [] | AnyTask[]): AnyTask { > [!NOTE] > This error type is not allowed to be subclassed. + + @template E The type of the rejection reasons. */ export class AggregateRejection extends Error { readonly name = 'AggregateRejection'; @@ -1108,7 +1119,14 @@ export class AggregateRejection extends Error { } } -/** @group Task Variants */ +/** + A {@linkcode Task Task} that has not yet resolved. + + @template T The type of the value when the `Task` resolves successfully. + @template E The type of the rejection reason when the `Task` rejects. + + @group Task Variants + */ export interface Pending extends Omit, 'value' | 'reason'> { get isPending(): true; get isResolved(): false; @@ -1116,7 +1134,14 @@ export interface Pending extends Omit, 'value' | 'reason'> get state(): typeof State.Pending; } -/** @group Task Variants */ +/** + A {@linkcode Task Task} that has resolved. Its `value` is of type `T`. + + @template T The type of the value when the `Task` resolves successfully. + @template E The type of the rejection reason when the `Task` rejects. + + @group Task Variants + */ export interface Resolved extends Omit, 'reason'> { get isPending(): false; get isResolved(): true; @@ -1125,7 +1150,14 @@ export interface Resolved extends Omit, 'reason'> { get value(): T; } -/** @group Task Variants */ +/** + A {@linkcode Task Task} that has rejected. Its `reason` is of type `E`. + + @template T The type of the value when the `Task` resolves successfully. + @template E The type of the rejection reason when the `Task` rejects. + + @group Task Variants + */ export interface Rejected extends Omit, 'value'> { get isPending(): false; get isResolved(): false; @@ -1303,6 +1335,9 @@ export const Task = TaskImpl as TaskConstructor; Result}. @class + + @template T The type of the value when the `Task` resolves successfully. + @template E The type of the rejection reason when the `Task` rejects. */ export type Task = Pending | Resolved | Rejected; export default Task;