Skip to content

Commit

Permalink
types(vest): remove void from Maybe<T> and update SuiteSelectors (
Browse files Browse the repository at this point in the history
  • Loading branch information
vonagam authored Dec 16, 2023
1 parent 4c34429 commit 7f336f0
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>
>;

2 comments on commit 7f336f0

@vercel
Copy link

@vercel vercel bot commented on 7f336f0 Dec 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

vest – ./website

vest-git-latest-ealush.vercel.app
vest-ealush.vercel.app
www.vestjs.dev
vest.vercel.app
vestjs.dev

@vercel
Copy link

@vercel vercel bot commented on 7f336f0 Dec 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

vest-next – ./website

vest-next.vercel.app
vest-website.vercel.app
vest-next-git-latest-ealush.vercel.app
vest-next-ealush.vercel.app

Please sign in to comment.