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 feccfd9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 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
6 changes: 2 additions & 4 deletions packages/vest/src/suiteResult/SummaryFailure.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Maybe } from 'vest-utils';

import { TIsolateTest } from 'IsolateTest';
import { TFieldName, TGroupName } from 'SuiteResultTypes';
import { WithFieldName } from 'TestTypes';
Expand All @@ -10,8 +8,8 @@ export class SummaryFailure<F extends TFieldName, G extends TGroupName>
{
constructor(
public fieldName: F,
public message: Maybe<string>,
public groupName: Maybe<G>
public message: string | undefined,
public groupName: G | undefined
) {}

static fromTestObject<F extends TFieldName, G extends TGroupName>(
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 feccfd9

Please sign in to comment.