import { type AnyFunction, type ComputedTypeError, type FixDeepFunctionInfer, type IsEqual, type Unwrap } from "../../../common"; import { type GetPropsWithValueExtends } from "../../../object"; import { type OnlyLiteralPrimitiveString } from "../../../clean/types/onlyLiteral"; import { type Primitive } from "../base"; type ComputeMatcher> = { [Prop in Unwrap]?: (value: GenericInput & Primitive) => unknown; }; type ForbiddenMoreKey, GenericMatcher extends ComputeMatcher> = Exclude> extends infer InferredKey ? IsEqual extends true ? unknown : ComputedTypeError<`Key "${Extract}" is forbidden.`> : never; type HandledKeys = Extract, string>; type OtherwiseValue, GenericMatcher extends object> = Extract, HandledKeys>>, any>; /** Performs partial pattern matching on a Clean string primitive and delegates unhandled values to an `otherwise` callback. /** /** **Supported call styles:** /** - Classic: `matchWithStringOtherwise(input, matcher, otherwise)` -> runs a matching handler or the fallback /** - Curried: `matchWithStringOtherwise(matcher, otherwise)` -> returns a function waiting for the primitive /** /** Raw string values are used as matcher keys. Handlers receive the original primitive narrowed to their key, and `otherwise` receives the same original primitive narrowed to all remaining values. /** /** ```ts /** const status = C.String.createOrThrow( /** "success" as "success" | "failure" | "pending", /** ); /** /** C.matchWithStringOtherwise( /** status, /** { /** success: () => 200, /** }, /** () => 500, /** ); // number /** /** pipe( /** status, /** C.matchWithStringOtherwise( /** { /** failure: () => "retry", /** }, /** (value) => value, /** ), /** ); // "retry" | C.Primitive<"success" | "pending"> /** /** const result = C.matchWithStringOtherwise( /** status, /** { /** success: (value) => value, /** failure: undefined, /** }, /** (value) => value, /** ); // C.Primitive<"success" | "failure" | "pending"> /** ``` /** /** @remarks Constraints and `NewType` metadata remain attached to the primitive passed to every callback. /** /** @see https://utils.duplojs.dev/en/v1/api/clean/primitives/operators/matchWithStringOtherwise /** @see [`C.matchWithString`](https://utils.duplojs.dev/en/v1/api/clean/primitives/operators/matchWithString) /** /** @namespace C /** */ export declare function matchWithStringOtherwise, GenericMatcher extends ComputeMatcher, GenericOutput>(matcher: FixDeepFunctionInfer>, GenericMatcher> & ForbiddenMoreKey, GenericMatcher>, otherwise: (value: OtherwiseValue) => GenericOutput): (input: GenericInput & OnlyLiteralPrimitiveString) => (ReturnType[keyof GenericMatcher], AnyFunction>> | GenericOutput); export declare function matchWithStringOtherwise, GenericMatcher extends ComputeMatcher, GenericOutput>(input: GenericInput & OnlyLiteralPrimitiveString, matcher: FixDeepFunctionInfer, GenericMatcher> & ForbiddenMoreKey, otherwise: (value: OtherwiseValue) => GenericOutput): (ReturnType> | GenericOutput); export {};