case 1
exportfunctiontest<Textendsobject,PextendskeyofT>(whatever: T,name: P): T[P]{constresult=Math.random()>0.5 ? whatever[name] : 'Hello!';// <-- expected T[P] | string, actual T[P]returnresult;// <-- returning unsound result}case 2
exportfunctiononeOrAnother<A,B>(one: A,another: B): A|B{returnMath.random()>0.5 ? one : another;}exportfunctiontest<Textendsobject,PextendskeyofT>(whatever: T,name: P): T[P]{constresult=oneOrAnother(whatever[name],'Hello!');// <-- result is clearly string | T[P] as expectedreturnresult;// <-- expected a type error, actual returning string | T[P] instead of T[P] no problem}
case 1
case 2