diff --git a/packages/context/src/context.ts b/packages/context/src/context.ts index 70be46347..a51d841e2 100644 --- a/packages/context/src/context.ts +++ b/packages/context/src/context.ts @@ -1,4 +1,4 @@ -import type { CB } from 'vest-utils'; +import type { CB, Maybe } from 'vest-utils'; import { assign, defaultTo, @@ -55,7 +55,7 @@ export function createContext(defaultContextValue?: T): CtxApi { * When nesting context runs, the the values of the current layer merges with the layers above it. */ export function createCascade>( - init?: (value: Partial, parentContext: T | void) => Nullable + init?: (value: Partial, parentContext: Maybe) => Nullable ): CtxCascadeApi { const ctx = createContext(); diff --git a/packages/n4s/src/runtime/enforceEager.ts b/packages/n4s/src/runtime/enforceEager.ts index 09bb4fd60..3745a879c 100644 --- a/packages/n4s/src/runtime/enforceEager.ts +++ b/packages/n4s/src/runtime/enforceEager.ts @@ -1,4 +1,4 @@ -import { invariant, StringObject, isNullish } from 'vest-utils'; +import { invariant, StringObject, isNullish, Maybe } from 'vest-utils'; import { ctx } from 'enforceContext'; import { getRule, RuleValue, Args, RuleBase } from 'runtimeRules'; @@ -16,7 +16,7 @@ export default function enforceEager(value: RuleValue): EnforceEagerReturn { const target = { message, } as EnforceEagerReturn; - let customMessage: string | undefined = undefined; + let customMessage: Maybe = undefined; // We create a proxy intercepting access to the target object (which is empty). const proxy: EnforceEagerReturn = new Proxy(target, { diff --git a/packages/n4s/src/runtime/genEnforceLazy.ts b/packages/n4s/src/runtime/genEnforceLazy.ts index ea7dc910f..a2a814447 100644 --- a/packages/n4s/src/runtime/genEnforceLazy.ts +++ b/packages/n4s/src/runtime/genEnforceLazy.ts @@ -1,4 +1,10 @@ -import { mapFirst, optionalFunctionValue, CB, Stringable } from 'vest-utils'; +import { + mapFirst, + optionalFunctionValue, + CB, + Stringable, + Maybe, +} from 'vest-utils'; import { ctx } from 'enforceContext'; import ruleReturn, { defaultToPassing, RuleDetailedResult } from 'ruleReturn'; @@ -8,7 +14,7 @@ import { transformResult } from 'transformResult'; // eslint-disable-next-line max-lines-per-function export default function genEnforceLazy(key: string) { const registeredRules: RegisteredRules = []; - let lazyMessage: void | LazyMessage; + let lazyMessage: Maybe; return addLazyRule(key); diff --git a/packages/vast/src/vast.ts b/packages/vast/src/vast.ts index 6e0574cd4..f8df143b1 100644 --- a/packages/vast/src/vast.ts +++ b/packages/vast/src/vast.ts @@ -1,4 +1,4 @@ -import { isFunction, optionalFunctionValue } from 'vest-utils'; +import { Maybe, isFunction, optionalFunctionValue } from 'vest-utils'; // eslint-disable-next-line max-lines-per-function export function createState( @@ -53,7 +53,7 @@ export function createState( function initKey( key: number, initialState?: StateInput, - prevState?: S | undefined + prevState?: Maybe ) { current().push(); set(key, optionalFunctionValue(initialState, prevState)); @@ -97,7 +97,7 @@ export type UseState = () => StateHandlerReturn; type CreateStateReturn = { reset: () => void; registerStateKey: ( - initialState?: StateInput | undefined, - onUpdate?: (() => void) | undefined + initialState?: Maybe>, + onUpdate?: Maybe<() => void> ) => () => StateHandlerReturn; }; diff --git a/packages/vest-utils/src/utilityTypes.ts b/packages/vest-utils/src/utilityTypes.ts index 58e970c4f..5926872f5 100644 --- a/packages/vest-utils/src/utilityTypes.ts +++ b/packages/vest-utils/src/utilityTypes.ts @@ -8,6 +8,8 @@ export type CB = (...args: any[]) => any; export type ValueOf = T[keyof T]; -export type Nullish = Nullable | undefined; +export type Nullish = Nullable | Maybe; export type Nullable = T | null; + +export type Maybe = T | undefined; diff --git a/packages/vest-utils/src/vest-utils.ts b/packages/vest-utils/src/vest-utils.ts index 85c8b9419..c875c444a 100644 --- a/packages/vest-utils/src/vest-utils.ts +++ b/packages/vest-utils/src/vest-utils.ts @@ -43,4 +43,5 @@ export type { ValueOf, Nullish, Nullable, + Maybe, } from 'utilityTypes'; diff --git a/packages/vest/src/core/Runtime.ts b/packages/vest/src/core/Runtime.ts index 0f84377a8..be7ced6ca 100644 --- a/packages/vest/src/core/Runtime.ts +++ b/packages/vest/src/core/Runtime.ts @@ -1,4 +1,4 @@ -import { CacheApi, TinyState, cache, seq, tinyState } from 'vest-utils'; +import { CacheApi, Maybe, TinyState, cache, seq, tinyState } from 'vest-utils'; import { VestRuntime } from 'vestjs-runtime'; import { @@ -15,7 +15,7 @@ type DoneCallbacks = Array; type StateExtra = { doneCallbacks: TinyState; fieldCallbacks: TinyState; - suiteName: string | undefined; + suiteName: Maybe; suiteId: string; suiteResultCache: CacheApi>; }; diff --git a/packages/vest/src/core/isolate/IsolateTest/IsolateTestReconciler.ts b/packages/vest/src/core/isolate/IsolateTest/IsolateTestReconciler.ts index f5fee4a6c..b0fa0f6a8 100644 --- a/packages/vest/src/core/isolate/IsolateTest/IsolateTestReconciler.ts +++ b/packages/vest/src/core/isolate/IsolateTest/IsolateTestReconciler.ts @@ -1,4 +1,4 @@ -import { Nullable, deferThrow, isNullish, text } from 'vest-utils'; +import { Maybe, Nullable, deferThrow, isNullish, text } from 'vest-utils'; import { IsolateInspector, Reconciler } from 'vestjs-runtime'; import type { Isolate } from 'vestjs-runtime'; @@ -110,7 +110,7 @@ function cancelOverriddenPendingTestOnTestReRun( function throwTestOrderError( newNode: IsolateTest, - prevNode: Isolate | undefined + prevNode: Maybe ): void { if (IsolateInspector.shouldAllowReorder(newNode)) { return; diff --git a/packages/vest/src/core/test/TestTypes.ts b/packages/vest/src/core/test/TestTypes.ts index 54e3e56cf..03d3090f1 100644 --- a/packages/vest/src/core/test/TestTypes.ts +++ b/packages/vest/src/core/test/TestTypes.ts @@ -1,8 +1,10 @@ +import { Maybe } from 'vest-utils'; + import { TFieldName } from 'SuiteResultTypes'; export type TestFn = () => TestResult; -export type AsyncTest = Promise; -export type TestResult = AsyncTest | boolean | void; +export type AsyncTest = Promise; +export type TestResult = Maybe; export type WithFieldName = { fieldName: F; diff --git a/packages/vest/src/core/test/helpers/matchingFieldName.ts b/packages/vest/src/core/test/helpers/matchingFieldName.ts index 06794095b..13868720d 100644 --- a/packages/vest/src/core/test/helpers/matchingFieldName.ts +++ b/packages/vest/src/core/test/helpers/matchingFieldName.ts @@ -1,16 +1,18 @@ +import { Maybe } from 'vest-utils'; + import { TFieldName } from 'SuiteResultTypes'; import { WithFieldName } from 'TestTypes'; export function nonMatchingFieldName( WithFieldName: WithFieldName, - fieldName?: TFieldName | void + fieldName?: Maybe ): boolean { return !!fieldName && !matchingFieldName(WithFieldName, fieldName); } export default function matchingFieldName( WithFieldName: WithFieldName, - fieldName?: TFieldName | void + fieldName?: Maybe ): boolean { return !!(fieldName && WithFieldName.fieldName === fieldName); } diff --git a/packages/vest/src/core/test/helpers/matchingGroupName.ts b/packages/vest/src/core/test/helpers/matchingGroupName.ts index a0fa6092f..c5e2e5901 100644 --- a/packages/vest/src/core/test/helpers/matchingGroupName.ts +++ b/packages/vest/src/core/test/helpers/matchingGroupName.ts @@ -1,4 +1,4 @@ -import { bindNot } from 'vest-utils'; +import { Maybe, bindNot } from 'vest-utils'; import { IsolateTest } from 'IsolateTest'; import { TGroupName } from 'SuiteResultTypes'; @@ -7,7 +7,7 @@ export const nonMatchingGroupName = bindNot(matchingGroupName); export function matchingGroupName( testObject: IsolateTest, - groupName: TGroupName | void + groupName: Maybe ): boolean { return testObject.groupName === groupName; } diff --git a/packages/vest/src/core/test/helpers/shouldUseErrorMessage.ts b/packages/vest/src/core/test/helpers/shouldUseErrorMessage.ts index be8956521..c29724f63 100644 --- a/packages/vest/src/core/test/helpers/shouldUseErrorMessage.ts +++ b/packages/vest/src/core/test/helpers/shouldUseErrorMessage.ts @@ -1,9 +1,9 @@ -import { isStringValue, isUndefined } from 'vest-utils'; +import { Maybe, isStringValue, isUndefined } from 'vest-utils'; export function shouldUseErrorAsMessage( - message: string | void, + message: Maybe, error: unknown -): error is string { +): error is Maybe { // kind of cheating with this safe guard, but it does the job return isUndefined(message) && isStringValue(error); } diff --git a/packages/vest/src/core/test/test.ts b/packages/vest/src/core/test/test.ts index 2223724cd..225b792af 100644 --- a/packages/vest/src/core/test/test.ts +++ b/packages/vest/src/core/test/test.ts @@ -1,4 +1,11 @@ -import { assign, invariant, isFunction, isStringValue, text } from 'vest-utils'; +import { + Maybe, + assign, + invariant, + isFunction, + isStringValue, + text, +} from 'vest-utils'; import { Bus, IsolateKey } from 'vestjs-runtime'; import { Events } from 'BusEvents'; @@ -38,7 +45,7 @@ function vestTest( ): IsolateTest { const [message, testFn, key] = ( isFunction(args[1]) ? args : [undefined, ...args] - ) as [string | undefined, TestFn, IsolateKey]; + ) as [Maybe, TestFn, IsolateKey]; validateTestParams(fieldName, testFn); diff --git a/packages/vest/src/hooks/exclusive.ts b/packages/vest/src/hooks/exclusive.ts index 0abb670c6..08560dcfd 100644 --- a/packages/vest/src/hooks/exclusive.ts +++ b/packages/vest/src/hooks/exclusive.ts @@ -3,6 +3,7 @@ import { asArray, hasOwnProperty, optionalFunctionValue, + Maybe, } from 'vest-utils'; import { ErrorStrings } from 'ErrorStrings'; @@ -11,9 +12,9 @@ import { TExclusion, useExclusion, useInclusion } from 'SuiteContext'; import { TFieldName, TGroupName } from 'SuiteResultTypes'; import { useIsExcludedIndividually } from 'skipWhen'; -export type ExclusionItem = string | string[] | undefined; -export type FieldExclusion = F | F[] | undefined; -export type GroupExclusion = G | G[] | undefined; +export type ExclusionItem = Maybe; +export type FieldExclusion = Maybe; +export type GroupExclusion = Maybe; /** * Adds a field or a list of fields into the inclusion list diff --git a/packages/vest/src/suiteResult/SuiteResultTypes.ts b/packages/vest/src/suiteResult/SuiteResultTypes.ts index 29daa9955..1ce161db5 100644 --- a/packages/vest/src/suiteResult/SuiteResultTypes.ts +++ b/packages/vest/src/suiteResult/SuiteResultTypes.ts @@ -1,3 +1,5 @@ +import { Maybe } from 'vest-utils'; + import { Severity } from 'Severity'; import { SummaryFailure } from 'SummaryFailure'; import { Done } from 'suiteRunResult'; @@ -54,7 +56,7 @@ export type SuiteRunResult< done: Done; }; -export type SuiteName = string | undefined; +export type SuiteName = Maybe; export type TFieldName = T; export type TGroupName = G; diff --git a/packages/vest/src/suiteResult/SummaryFailure.ts b/packages/vest/src/suiteResult/SummaryFailure.ts index d3cc09b04..f7fe8c7cf 100644 --- a/packages/vest/src/suiteResult/SummaryFailure.ts +++ b/packages/vest/src/suiteResult/SummaryFailure.ts @@ -1,3 +1,5 @@ +import { Maybe } from 'vest-utils'; + import { IsolateTest } from 'IsolateTest'; import { TFieldName, TGroupName } from 'SuiteResultTypes'; import { WithFieldName } from 'TestTypes'; @@ -7,8 +9,8 @@ export class SummaryFailure { constructor( public fieldName: F, - public message: string | undefined, - public groupName: G | undefined + public message: Maybe, + public groupName: Maybe ) {} static fromTestObject( diff --git a/packages/vest/src/suiteResult/done/shouldSkipDoneRegistration.ts b/packages/vest/src/suiteResult/done/shouldSkipDoneRegistration.ts index dee6dba73..16e7c1ae8 100644 --- a/packages/vest/src/suiteResult/done/shouldSkipDoneRegistration.ts +++ b/packages/vest/src/suiteResult/done/shouldSkipDoneRegistration.ts @@ -2,7 +2,7 @@ * DONE is here and not in its own module to prevent circular dependency issues. */ -import { isFunction, numberEquals } from 'vest-utils'; +import { Maybe, isFunction, numberEquals } from 'vest-utils'; import { SuiteResult, @@ -17,7 +17,7 @@ export function shouldSkipDoneRegistration< >( callback: (res: SuiteResult) => void, - fieldName: F | undefined, + fieldName: Maybe, output: SuiteRunResult ): boolean { // If we do not have any test runs for the current field diff --git a/packages/vest/src/suiteResult/selectors/produceSuiteSummary.ts b/packages/vest/src/suiteResult/selectors/produceSuiteSummary.ts index edf97b5bd..a4c9de57d 100644 --- a/packages/vest/src/suiteResult/selectors/produceSuiteSummary.ts +++ b/packages/vest/src/suiteResult/selectors/produceSuiteSummary.ts @@ -1,4 +1,4 @@ -import { assign, defaultTo } from 'vest-utils'; +import { Maybe, assign, defaultTo } from 'vest-utils'; import { IsolateTest } from 'IsolateTest'; import { countKeyBySeverity, Severity } from 'Severity'; @@ -136,7 +136,7 @@ function countFailures( * functions as it is really the same, with the difference of "valid" missing in groups */ function appendTestObject( - summaryKey: SingleTestSummary | undefined, + summaryKey: Maybe, testObject: IsolateTest ): SingleTestSummary { const { message } = testObject; diff --git a/packages/vest/src/suiteResult/selectors/suiteSelectors.ts b/packages/vest/src/suiteResult/selectors/suiteSelectors.ts index 3043acbd9..54478fa2d 100644 --- a/packages/vest/src/suiteResult/selectors/suiteSelectors.ts +++ b/packages/vest/src/suiteResult/selectors/suiteSelectors.ts @@ -1,4 +1,4 @@ -import { isPositive } from 'vest-utils'; +import { Maybe, isPositive } from 'vest-utils'; import { Severity, SeverityCount } from 'Severity'; import { @@ -47,7 +47,7 @@ export function bindSuiteSelectors( isValidByGroup: ( ...args: Parameters['isValidByGroup']> ) => get().isValidByGroup(...args), - } as unknown as SuiteSelectors; + } as SuiteSelectors; } // eslint-disable-next-line max-lines-per-function, max-statements @@ -136,7 +136,7 @@ export function suiteSelectors( return getFailures(summary, Severity.WARNINGS, fieldName); } - function getWarning(fieldName?: F): void | string | SummaryFailure { + function getWarning(fieldName?: F): Maybe> { return getFailure(Severity.WARNINGS, summary, fieldName as F); } @@ -146,7 +146,7 @@ export function suiteSelectors( return getFailures(summary, Severity.ERRORS, fieldName); } - function getError(fieldName?: F): void | string | SummaryFailure { + function getError(fieldName?: F): Maybe> { return getFailure(Severity.ERRORS, summary, fieldName as F); } @@ -167,8 +167,8 @@ export function suiteSelectors( } export interface SuiteSelectors { - getWarning(fieldName?: F): void | string | SummaryFailure; - getError(fieldName?: F): void | string | SummaryFailure; + getWarning(fieldName?: F): Maybe>; + getError(fieldName?: F): Maybe>; getErrors(fieldName: F): string[]; getErrors(): FailureMessages; getWarnings(): FailureMessages; @@ -266,17 +266,17 @@ function hasFailures( function getFailure( severity: Severity, summary: SuiteSummary -): SummaryFailure | undefined; +): Maybe>; function getFailure( severity: Severity, summary: SuiteSummary, fieldName: F -): string | undefined; +): Maybe; function getFailure( severity: Severity, summary: SuiteSummary, fieldName?: F -): SummaryFailure | string | undefined { +): Maybe | string> { const summaryKey = summary[severity]; if (!fieldName) {