@@ -1004,3 +1004,136 @@ function h<T extends 1 | 2>(x: T): T extends 1 ? number : T extends 2 ? string :
1004
1004
}
1005
1005
return 0; // Ok
1006
1006
}
1007
+
1008
+ // From #33912
1009
+ abstract class Operation<T, R> {
1010
+ >Operation : Symbol(Operation, Decl(dependentReturnType1.ts, 357, 1))
1011
+ >T : Symbol(T, Decl(dependentReturnType1.ts, 360, 25))
1012
+ >R : Symbol(R, Decl(dependentReturnType1.ts, 360, 27))
1013
+
1014
+ abstract perform(t: T): R;
1015
+ >perform : Symbol(Operation.perform, Decl(dependentReturnType1.ts, 360, 32))
1016
+ >t : Symbol(t, Decl(dependentReturnType1.ts, 361, 21))
1017
+ >T : Symbol(T, Decl(dependentReturnType1.ts, 360, 25))
1018
+ >R : Symbol(R, Decl(dependentReturnType1.ts, 360, 27))
1019
+ }
1020
+
1021
+ type ConditionalReturnType<T, R, EOp extends Operation<T, R> | undefined> =
1022
+ >ConditionalReturnType : Symbol(ConditionalReturnType, Decl(dependentReturnType1.ts, 362, 1))
1023
+ >T : Symbol(T, Decl(dependentReturnType1.ts, 364, 27))
1024
+ >R : Symbol(R, Decl(dependentReturnType1.ts, 364, 29))
1025
+ >EOp : Symbol(EOp, Decl(dependentReturnType1.ts, 364, 32))
1026
+ >Operation : Symbol(Operation, Decl(dependentReturnType1.ts, 357, 1))
1027
+ >T : Symbol(T, Decl(dependentReturnType1.ts, 364, 27))
1028
+ >R : Symbol(R, Decl(dependentReturnType1.ts, 364, 29))
1029
+
1030
+ EOp extends Operation<T, R> ? R : EOp extends undefined ? T | R : T | R;
1031
+ >EOp : Symbol(EOp, Decl(dependentReturnType1.ts, 364, 32))
1032
+ >Operation : Symbol(Operation, Decl(dependentReturnType1.ts, 357, 1))
1033
+ >T : Symbol(T, Decl(dependentReturnType1.ts, 364, 27))
1034
+ >R : Symbol(R, Decl(dependentReturnType1.ts, 364, 29))
1035
+ >R : Symbol(R, Decl(dependentReturnType1.ts, 364, 29))
1036
+ >EOp : Symbol(EOp, Decl(dependentReturnType1.ts, 364, 32))
1037
+ >T : Symbol(T, Decl(dependentReturnType1.ts, 364, 27))
1038
+ >R : Symbol(R, Decl(dependentReturnType1.ts, 364, 29))
1039
+ >T : Symbol(T, Decl(dependentReturnType1.ts, 364, 27))
1040
+ >R : Symbol(R, Decl(dependentReturnType1.ts, 364, 29))
1041
+
1042
+ class ConditionalOperation<T, R, EOp extends Operation<T, R> | undefined> extends Operation<T, ConditionalReturnType<T, R, EOp>> {
1043
+ >ConditionalOperation : Symbol(ConditionalOperation, Decl(dependentReturnType1.ts, 365, 76))
1044
+ >T : Symbol(T, Decl(dependentReturnType1.ts, 367, 27))
1045
+ >R : Symbol(R, Decl(dependentReturnType1.ts, 367, 29))
1046
+ >EOp : Symbol(EOp, Decl(dependentReturnType1.ts, 367, 32))
1047
+ >Operation : Symbol(Operation, Decl(dependentReturnType1.ts, 357, 1))
1048
+ >T : Symbol(T, Decl(dependentReturnType1.ts, 367, 27))
1049
+ >R : Symbol(R, Decl(dependentReturnType1.ts, 367, 29))
1050
+ >Operation : Symbol(Operation, Decl(dependentReturnType1.ts, 357, 1))
1051
+ >T : Symbol(T, Decl(dependentReturnType1.ts, 367, 27))
1052
+ >ConditionalReturnType : Symbol(ConditionalReturnType, Decl(dependentReturnType1.ts, 362, 1))
1053
+ >T : Symbol(T, Decl(dependentReturnType1.ts, 367, 27))
1054
+ >R : Symbol(R, Decl(dependentReturnType1.ts, 367, 29))
1055
+ >EOp : Symbol(EOp, Decl(dependentReturnType1.ts, 367, 32))
1056
+
1057
+ constructor(
1058
+ private predicate: (value: T) => boolean,
1059
+ >predicate : Symbol(ConditionalOperation.predicate, Decl(dependentReturnType1.ts, 368, 16))
1060
+ >value : Symbol(value, Decl(dependentReturnType1.ts, 369, 28))
1061
+ >T : Symbol(T, Decl(dependentReturnType1.ts, 367, 27))
1062
+
1063
+ private thenOp: Operation<T, R>,
1064
+ >thenOp : Symbol(ConditionalOperation.thenOp, Decl(dependentReturnType1.ts, 369, 49))
1065
+ >Operation : Symbol(Operation, Decl(dependentReturnType1.ts, 357, 1))
1066
+ >T : Symbol(T, Decl(dependentReturnType1.ts, 367, 27))
1067
+ >R : Symbol(R, Decl(dependentReturnType1.ts, 367, 29))
1068
+
1069
+ private elseOp?: EOp
1070
+ >elseOp : Symbol(ConditionalOperation.elseOp, Decl(dependentReturnType1.ts, 370, 40))
1071
+ >EOp : Symbol(EOp, Decl(dependentReturnType1.ts, 367, 32))
1072
+
1073
+ ) {
1074
+ super();
1075
+ >super : Symbol(Operation, Decl(dependentReturnType1.ts, 357, 1))
1076
+ }
1077
+
1078
+ perform(t: T): ConditionalReturnType<T, R, EOp> {
1079
+ >perform : Symbol(ConditionalOperation.perform, Decl(dependentReturnType1.ts, 374, 5))
1080
+ >t : Symbol(t, Decl(dependentReturnType1.ts, 376, 12))
1081
+ >T : Symbol(T, Decl(dependentReturnType1.ts, 367, 27))
1082
+ >ConditionalReturnType : Symbol(ConditionalReturnType, Decl(dependentReturnType1.ts, 362, 1))
1083
+ >T : Symbol(T, Decl(dependentReturnType1.ts, 367, 27))
1084
+ >R : Symbol(R, Decl(dependentReturnType1.ts, 367, 29))
1085
+ >EOp : Symbol(EOp, Decl(dependentReturnType1.ts, 367, 32))
1086
+
1087
+ if (this.predicate(t)) {
1088
+ >this.predicate : Symbol(ConditionalOperation.predicate, Decl(dependentReturnType1.ts, 368, 16))
1089
+ >this : Symbol(ConditionalOperation, Decl(dependentReturnType1.ts, 365, 76))
1090
+ >predicate : Symbol(ConditionalOperation.predicate, Decl(dependentReturnType1.ts, 368, 16))
1091
+ >t : Symbol(t, Decl(dependentReturnType1.ts, 376, 12))
1092
+
1093
+ return this.thenOp.perform(t); // Bad: this is assignable to all of the branches of the conditional, but we still can't return it
1094
+ >this.thenOp.perform : Symbol(Operation.perform, Decl(dependentReturnType1.ts, 360, 32))
1095
+ >this.thenOp : Symbol(ConditionalOperation.thenOp, Decl(dependentReturnType1.ts, 369, 49))
1096
+ >this : Symbol(ConditionalOperation, Decl(dependentReturnType1.ts, 365, 76))
1097
+ >thenOp : Symbol(ConditionalOperation.thenOp, Decl(dependentReturnType1.ts, 369, 49))
1098
+ >perform : Symbol(Operation.perform, Decl(dependentReturnType1.ts, 360, 32))
1099
+ >t : Symbol(t, Decl(dependentReturnType1.ts, 376, 12))
1100
+
1101
+ } else if (typeof this.elseOp !== 'undefined') {
1102
+ >this.elseOp : Symbol(ConditionalOperation.elseOp, Decl(dependentReturnType1.ts, 370, 40))
1103
+ >this : Symbol(ConditionalOperation, Decl(dependentReturnType1.ts, 365, 76))
1104
+ >elseOp : Symbol(ConditionalOperation.elseOp, Decl(dependentReturnType1.ts, 370, 40))
1105
+
1106
+ return this.elseOp.perform(t); // Ok
1107
+ >this.elseOp.perform : Symbol(Operation.perform, Decl(dependentReturnType1.ts, 360, 32))
1108
+ >this.elseOp : Symbol(ConditionalOperation.elseOp, Decl(dependentReturnType1.ts, 370, 40))
1109
+ >this : Symbol(ConditionalOperation, Decl(dependentReturnType1.ts, 365, 76))
1110
+ >elseOp : Symbol(ConditionalOperation.elseOp, Decl(dependentReturnType1.ts, 370, 40))
1111
+ >perform : Symbol(Operation.perform, Decl(dependentReturnType1.ts, 360, 32))
1112
+ >t : Symbol(t, Decl(dependentReturnType1.ts, 376, 12))
1113
+
1114
+ } else {
1115
+ return t; // Ok
1116
+ >t : Symbol(t, Decl(dependentReturnType1.ts, 376, 12))
1117
+ }
1118
+ }
1119
+ }
1120
+
1121
+ // Optional tuple element
1122
+ function tupl<T extends true | false | undefined>(x: [string, some?: T]):
1123
+ >tupl : Symbol(tupl, Decl(dependentReturnType1.ts, 385, 1))
1124
+ >T : Symbol(T, Decl(dependentReturnType1.ts, 388, 14))
1125
+ >x : Symbol(x, Decl(dependentReturnType1.ts, 388, 50))
1126
+ >T : Symbol(T, Decl(dependentReturnType1.ts, 388, 14))
1127
+
1128
+ T extends true ? 1 : T extends false | undefined ? 2 : 1 | 2 {
1129
+ >T : Symbol(T, Decl(dependentReturnType1.ts, 388, 14))
1130
+ >T : Symbol(T, Decl(dependentReturnType1.ts, 388, 14))
1131
+
1132
+ if (x[1]) {
1133
+ >x : Symbol(x, Decl(dependentReturnType1.ts, 388, 50))
1134
+ >1 : Symbol(1)
1135
+
1136
+ return 1;
1137
+ }
1138
+ return 2;
1139
+ }
0 commit comments