Type alias narrow<input, pattern>

narrow<input, pattern>: ExtractPreciseValue<input, InvertPattern<pattern, input>>

P.narrow<Input, Pattern> will narrow the input type to only keep the set of values that are compatible with the provided pattern type.

Read the documentation for P.narrow on GitHub

Type Parameters

Example

type Input = ['a' | 'b' | 'c', 'a' | 'b' | 'c']
const Pattern = ['a', P.union('a', 'b')] as const

type Narrowed = P.narrow<Input, typeof Pattern>
// ^? ['a', 'a' | 'b']