const hasName = isMatching({ name: P.string })
declare let input: unknown
if (hasName(input)) {
// `input` inferred as { name: string }
return input.name
}
isMatching
takes pattern and a value and checks if the value matches this pattern.
declare let input: unknown
if (isMatching({ name: P.string }, input)) {
// `input` inferred as { name: string }
return input.name
}
isMatching
takes pattern and returns a type guard function, cheching if a value matches this pattern.Read documentation for
isMatching
on GitHub