<R extends object, P extends keyof R, const V extends R[P]>(obj: R, property: P, value: V): asserts obj is Extract<R, Record<P, V>> Narrows a discriminated union by a literal property value, failing the test if the value doesn't match. The assertion signature propagates the narrowed type so callers can access variant-specific fields directly.
Works with any discriminator key (kind, ok, type, _tag, etc.).
obj
Rproperty
Pvalue
Vreturns
void generics
R
objectP
keyof RV
R[P]examples
type Shape =
| {kind: 'circle'; radius: number}
| {kind: 'square'; side: number};
const shape: Shape = get_shape();
assert_property(shape, 'kind', 'circle');
assert.strictEqual(shape.radius, 5); // `radius` now typed as `number`