Open
Description
π Search Terms
specify type narrow union
π Version & Regression Information
All versions I checked and nothing in FAQ that seems related
β― Playground Link
π» Code
// Use the variance annotation to force this type to be invariant, even though it would otherwise be covariant
type Invariant<in out T> = () => T;
const foo = <T extends object>(obj: T): Invariant<{[P in keyof T]: Invariant<T[P]>}> => null!;
const bar = <T extends {[P in keyof T]: Invariant<any>}>(w: T): T => null!;
const inferred = bar({a: foo({b: true})}); // true is boolean as expected
// Explicitly specify the generic param
const explicit = bar<{
a: Invariant<{
b: Invariant<boolean>;
}>
}>({a: foo({b: true})}); // narrowed to true instead of boolean and errors
π Actual behavior
Narrows to true
π Expected behavior
Should stay boolean
Additional information about the issue
Doing as boolean
works...