file.ts(28,26): error TS2322: Type 'true' is not assignable to type 'SomeInterfaceBad<T>[U]'.
  Type 'true' is not assignable to type 'T extends 1 ? true : T extends 2 ? false : never'.
file.ts(28,33): error TS2322: Type 'false' is not assignable to type 'SomeInterfaceBad<T>[U]'.
  Type 'false' is not assignable to type 'T extends 1 ? true : T extends 2 ? false : never'.
file.ts(30,16): error TS2322: Type '1' is not assignable to type 'SomeInterfaceBad<T>[U]'.
  Type '1' is not assignable to type 'T extends true ? 1 : T extends false ? 2 : never'.
file.ts(30,20): error TS2322: Type '2' is not assignable to type 'SomeInterfaceBad<T>[U]'.
  Type '2' is not assignable to type 'T extends true ? 1 : T extends false ? 2 : never'.
file.ts(80,13): error TS2322: Type '1' is not assignable to type 'this extends Sub1 ? 1 : this extends Sub2 ? 2 : never'.
file.ts(82,9): error TS2322: Type '2' is not assignable to type 'this extends Sub1 ? 1 : this extends Sub2 ? 2 : never'.
file.ts(94,16): error TS2322: Type '1' is not assignable to type 'T extends true ? 1 : T extends false ? 2 : never'.
file.ts(94,20): error TS2322: Type '2' is not assignable to type 'T extends true ? 1 : T extends false ? 2 : never'.
file.ts(98,100): error TS2322: Type '1 | 2' is not assignable to type 'T extends true ? 1 : T extends false ? 2 : never'.
  Type '1' is not assignable to type 'T extends true ? 1 : T extends false ? 2 : never'.
file.ts(106,9): error TS2322: Type 'number' is not assignable to type 'SomeCond<T>'.
file.ts(106,9): error TS2589: Type instantiation is excessively deep and possibly infinite.
file.ts(108,5): error TS2322: Type 'number' is not assignable to type 'SomeCond<T>'.
file.ts(114,60): error TS2366: Function lacks ending return statement and return type does not include 'undefined'.
file.ts(116,9): error TS2322: Type '"one"' is not assignable to type 'OtherCond<U> | OtherCond<V>'.
file.ts(126,9): error TS2322: Type '"a"' is not assignable to type 'T extends (infer P)[] ? P : T extends number ? undefined : never'.
file.ts(128,5): error TS2322: Type 'undefined' is not assignable to type 'T extends (infer P)[] ? P : T extends number ? undefined : never'.


==== file.ts (16 errors) ====
    // Type parameter in outer scope
    function outer<T extends boolean>(x: T): number {
        return inner();
    
        function inner(): T extends true ? 1 : T extends false ? 2 : never {
            return x ? 1 : 2;
        }
    }
    
    // Overloads
    function fun6<T extends boolean>(x: T, y: string): T extends true ? string : T extends false ? 2 : never;
    function fun6<T extends boolean>(x: T, y: undefined): T extends true ? 1 : T extends false ? 2 : never;
    function fun6(x: boolean): 1 | 2 | string;
    function fun6<T extends boolean>(x: T, y?: string): T extends true ? 1 | string : T extends false ? 2 : never {
        return x ? y !== undefined ? y : 1 : 2;
    }
    
    // Indexed access with conditional inside
    
    // DOESN'T NARROW the nested conditional type of wrong shape
    interface SomeInterfaceBad<T> {
        prop1: T extends 1 ? true : T extends 2 ? false : never;
        prop2: T extends true ? 1 : T extends false ? 2 : never;
    }
    
    function fun4bad<T, U extends keyof SomeInterfaceBad<unknown>>(x: T, y: U): SomeInterfaceBad<T>[U] {
        if (y === "prop1") {
            return x === 1 ? true : false;
                             ~~~~
!!! error TS2322: Type 'true' is not assignable to type 'SomeInterfaceBad<T>[U]'.
!!! error TS2322:   Type 'true' is not assignable to type 'T extends 1 ? true : T extends 2 ? false : never'.
                                    ~~~~~
!!! error TS2322: Type 'false' is not assignable to type 'SomeInterfaceBad<T>[U]'.
!!! error TS2322:   Type 'false' is not assignable to type 'T extends 1 ? true : T extends 2 ? false : never'.
        }
        return x ? 1 : 2;
                   ~
!!! error TS2322: Type '1' is not assignable to type 'SomeInterfaceBad<T>[U]'.
!!! error TS2322:   Type '1' is not assignable to type 'T extends true ? 1 : T extends false ? 2 : never'.
                       ~
!!! error TS2322: Type '2' is not assignable to type 'SomeInterfaceBad<T>[U]'.
!!! error TS2322:   Type '2' is not assignable to type 'T extends true ? 1 : T extends false ? 2 : never'.
    }
    
    // Narrows nested conditional type of right shape
    interface SomeInterfaceGood<T> {
        prop1: T extends true ? 2 : T extends false ? 1 : never;
        prop2: T extends true ? 1 : T extends false ? 2 : never;
    }
    
    function fun4good<T extends boolean, U extends keyof SomeInterfaceGood<unknown>>(x: T, y: U): SomeInterfaceGood<T>[U] {
        if (y === "prop1") {
            return x ? 2 : 1;
        }
        return x ? 1 : 2;
    }
    
    // Indexed access with indexed access inside - OK, narrows
    interface BB {
        "a": number;
        "b": string;
    }
    
    interface AA<T extends keyof BB> {
        "c": BB[T];
        "d": boolean,
    }
    
    function reduction<T extends keyof BB, U extends keyof AA<any>>(x: T, y: U): AA<T>[U] {
        if (x === "a" && y === "c") {
            return 0; // Ok
        }
    
        return undefined as never;
    }
    
    // Conditional with indexed access inside - OK, narrows
    function fun5<T extends 1 | 2, U extends keyof BB>(x: T, y: U): T extends 1 ? BB[U] : T extends 2 ? boolean : never {
        if (x === 1) {
            if (y === "a") {
                return 0;
            }
            return "";
        }
        return true;
    }
    
    // `this` type parameter - Doesn't narrow
    abstract class SomeClass {
        fun3(this: Sub1 | Sub2): this extends Sub1 ? 1 : this extends Sub2 ? 2 : never {
            if (this instanceof Sub1) {
                return 1;
                ~~~~~~
!!! error TS2322: Type '1' is not assignable to type 'this extends Sub1 ? 1 : this extends Sub2 ? 2 : never'.
            }
            return 2;
            ~~~~~~
!!! error TS2322: Type '2' is not assignable to type 'this extends Sub1 ? 1 : this extends Sub2 ? 2 : never'.
        }
    }
    class Sub1 extends SomeClass {
        #sub1!: symbol;
    };
    class Sub2 extends SomeClass {
        #sub2!: symbol;
    };
    
    // Detection of type parameter reference in presence of typeof
    function fun2<T extends boolean>(x: T, y: typeof x): T extends true ? 1 : T extends false ? 2 : never {
        return x ? 1 : 2;
                   ~
!!! error TS2322: Type '1' is not assignable to type 'T extends true ? 1 : T extends false ? 2 : never'.
                       ~
!!! error TS2322: Type '2' is not assignable to type 'T extends true ? 1 : T extends false ? 2 : never'.
    }
    
    // Contextually-typed lambdas
    const fun1: <T extends boolean>(x: T) => T extends true ? 1 : T extends false ? 2 : never = (x) => x ? 1 : 2;
                                                                                                       ~~~~~~~~~
!!! error TS2322: Type '1 | 2' is not assignable to type 'T extends true ? 1 : T extends false ? 2 : never'.
!!! error TS2322:   Type '1' is not assignable to type 'T extends true ? 1 : T extends false ? 2 : never'.
!!! related TS6502 file.ts:98:13: The expected type comes from the return type of this signature.
    
    
    // Circular conditionals
    type SomeCond<T> = T extends true ? 1 : T extends false ? SomeCond<T> : never;
    
    function f7<T extends boolean>(x: T): SomeCond<T> {
        if (x) {
            return 1;
            ~~~~~~
!!! error TS2322: Type 'number' is not assignable to type 'SomeCond<T>'.
            ~~~~~~
!!! error TS2589: Type instantiation is excessively deep and possibly infinite.
        }
        return 2;
        ~~~~~~
!!! error TS2322: Type 'number' is not assignable to type 'SomeCond<T>'.
    }
    
    // Composite instantiation of conditional type
    type OtherCond<T> = T extends 1 ? "one" : T extends 2 ? "two" : T extends 3 ? "three" : T extends 4 ? "four" : never;
    
    function f8<U extends 1 | 2, V extends 3 | 4>(x: U, y: V): OtherCond<U | V> {
                                                               ~~~~~~~~~~~~~~~~
!!! error TS2366: Function lacks ending return statement and return type does not include 'undefined'.
        if (x === 1 && y === 3)  {
            return "one";
            ~~~~~~
!!! error TS2322: Type '"one"' is not assignable to type 'OtherCond<U> | OtherCond<V>'.
        }
    }
    
    // Conditionals with `infer` - will not narrow, it is not safe to infer from the narrowed type into an `infer` type parameter
    function f9<T extends "a"[] | "b"[] | number>(x: T): T extends Array<infer P> ? P : T extends number ? undefined : never {
        if (Array.isArray(x)) {
            // If we allowed narrowing of the conditional return type, when resolving the conditional `T & ("a"[] | "b"[]) extends Array<infer P> ? P : ...`,
            // we could infer `"a" | "b"` for `P`, and allow "a" to be returned. However, when calling `f10`, `T` could be instantiated with `"b"[]`, and the return type would be `"b"`,
            // so allowing an `"a"` return would be unsound.
            return "a";
            ~~~~~~
!!! error TS2322: Type '"a"' is not assignable to type 'T extends (infer P)[] ? P : T extends number ? undefined : never'.
        }
        return undefined;
        ~~~~~~
!!! error TS2322: Type 'undefined' is not assignable to type 'T extends (infer P)[] ? P : T extends number ? undefined : never'.
    }
    
    