Skip to content

Commit

Permalink
types: remove void from Maybe<T> and update SuiteSelectors
Browse files Browse the repository at this point in the history
  • Loading branch information
vonagam committed Dec 15, 2023
1 parent 4c34429 commit ce83094
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/vest-utils/src/utilityTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type Nullish<T = void> = Nullable<T> | Maybe<T>;

export type Nullable<T> = T | null;

export type Maybe<T> = T | undefined | void;
export type Maybe<T> = T | undefined;

export type OneOrMoreOf<T> = T | T[];

Expand Down
2 changes: 1 addition & 1 deletion packages/vest/src/core/test/TestTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type TestFnPayload = { signal: AbortSignal };

export type TestFn = (payload: TestFnPayload) => TestResult;
export type AsyncTest = Promise<void>;
export type TestResult = Maybe<AsyncTest | boolean>;
export type TestResult = Maybe<AsyncTest | boolean> | void;

export type WithFieldName<F extends TFieldName = TFieldName> = {
fieldName: F;
Expand Down
20 changes: 8 additions & 12 deletions packages/vest/src/suiteResult/selectors/suiteSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export function suiteSelectors<F extends TFieldName, G extends TGroupName>(

function getWarning(): Maybe<SummaryFailure<F, G>>;
function getWarning(fieldName: F): Maybe<string>;
function getWarning(fieldName?: F): GetSingularResponse<F, G> {
function getWarning(fieldName?: F): Maybe<SummaryFailure<F, G> | string> {
return getFailure<F, G>(Severity.WARNINGS, summary, fieldName as F);
}

Expand All @@ -161,7 +161,7 @@ export function suiteSelectors<F extends TFieldName, G extends TGroupName>(

function getError(): Maybe<SummaryFailure<F, G>>;
function getError(fieldName: F): Maybe<string>;
function getError(fieldName?: F): GetSingularResponse<F, G> {
function getError(fieldName?: F): Maybe<SummaryFailure<F, G> | string> {
return getFailure<F, G>(Severity.ERRORS, summary, fieldName as F);
}

Expand All @@ -188,12 +188,12 @@ export function suiteSelectors<F extends TFieldName, G extends TGroupName>(
}

export interface SuiteSelectors<F extends TFieldName, G extends TGroupName> {
getWarning(): Maybe<SummaryFailure<F, G>>;
getWarning(fieldName: F): Maybe<string>;
getWarning(fieldName?: F): GetSingularResponse<F, G>;
getError(): Maybe<SummaryFailure<F, G>>;
getError(fieldName: F): Maybe<string>;
getError(fieldName?: F): GetSingularResponse<F, G>;
getWarning(): SummaryFailure<F, G> | undefined;
getWarning(fieldName: F): string | undefined;
getWarning(fieldName?: F): SummaryFailure<F, G> | string | undefined;
getError(): SummaryFailure<F, G> | undefined;
getError(fieldName: F): string | undefined;
getError(fieldName?: F): SummaryFailure<F, G> | string | undefined;
getErrors(): FailureMessages;
getErrors(fieldName: F): string[];
getErrors(fieldName?: F): string[] | FailureMessages;
Expand Down Expand Up @@ -319,7 +319,3 @@ function getFailure<F extends TFieldName, G extends TGroupName>(
matchingFieldName(summaryFailure, fieldName)
)?.message;
}

type GetSingularResponse<F extends TFieldName, G extends TGroupName> = Maybe<
string | SummaryFailure<F, G>
>;

0 comments on commit ce83094

Please sign in to comment.