UNPKG

@cuppachino/ts-pattern

Version:

The exhaustive Pattern Matching library for TypeScript.

34 lines (33 loc) 1.22 kB
import { Pattern } from './types/Pattern.js'; import { MatchedValue } from './types/Match.js'; import * as P from './patterns.js'; /** * `isMatching` takes pattern and returns a **type guard** function, cheching if a value matches this pattern. * * [Read documentation for `isMatching` on GitHub](https://github.com/gvergnaud/ts-pattern#ismatching) * * @example * const hasName = isMatching({ name: P.string }) * * declare let input: unknown * * if (hasName(input)) { * // `input` inferred as { name: string } * return input.name * } */ export declare function isMatching<p extends Pattern<any>>(pattern: p): (value: any) => value is MatchedValue<any, P.infer<p>>; /** * `isMatching` takes pattern and a value and checks if the value matches this pattern. * * [Read documentation for `isMatching` on GitHub](https://github.com/gvergnaud/ts-pattern#ismatching) * * @example * declare let input: unknown * * if (isMatching({ name: P.string }, input)) { * // `input` inferred as { name: string } * return input.name * } */ export declare function isMatching<p extends Pattern<any>>(pattern: p, value: any): value is MatchedValue<any, P.infer<p>>;