matchWithStringOtherwise
matchWithStringOtherwise() traite certains membres d’une union de chaînes littérales. Les clés du matcher doivent appartenir à l’union d’entrée, mais certains cas peuvent être omis. Le callback otherwise reçoit uniquement les littéraux sans handler.
Exemple interactif
Syntaxe
Signature classique
typescript
function matchWithStringOtherwise<Input extends string, Matcher, Output>(
input: Input,
matcher: Matcher,
otherwise: (value: UnhandledValues) => Output
): MatcherResult | OutputSignature currifiée
typescript
function matchWithStringOtherwise<Input extends string, Matcher, Output>(
matcher: Matcher,
otherwise: (value: UnhandledValues) => Output
): (input: Input) => MatcherResult | OutputParamètres
input: une chaîne littérale ou une union de littéraux ; le type largestringest refusé.matcher: un objet partiel dont les clés doivent appartenir àinput. Une propriété peut valoirundefinedpour rediriger ce cas versotherwise.otherwise: reçoit l’union exacte des cas sans handler.
Valeur de retour
Le résultat du handler sélectionné, ou celui d’otherwise pour une valeur non traitée.
Voir aussi
matchWithString- Matching exhaustif de chaînes.matchWithNumberOtherwise- Matching partiel numérique.
